diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-04-03 20:01:41 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-04-03 20:01:41 +0000 |
commit | 633e4a00e66da6f91dca539441b44dd018270df9 (patch) | |
tree | 92079d3f7e3355d1514cfd6ca164bcc24fc42dfc /lib | |
parent | 25209273d33de5d690b0c89b4a462b979bfd4324 (diff) | |
download | redmine-633e4a00e66da6f91dca539441b44dd018270df9.tar.gz redmine-633e4a00e66da6f91dca539441b44dd018270df9.zip |
Check that the SCM log file is writable before using it (#13541).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11698 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/scm/adapters/abstract_adapter.rb | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 365987326..3e51f2d4d 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -219,17 +219,38 @@ module Redmine end # Path to the file where scm stderr output is logged + # Returns nil if the log file is not writable def self.stderr_log_file - @stderr_log_path ||= - Redmine::Configuration['scm_stderr_log_file'].presence || - Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s + if @stderr_log_file.nil? + writable = false + path = Redmine::Configuration['scm_stderr_log_file'].presence + path ||= Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s + if File.exists?(path) + if File.file?(path) && File.writable?(path) + writable = true + else + logger.warn("SCM log file (#{path}) is not writable") + end + else + begin + File.open(path, "w") {} + writable = true + rescue => e + logger.warn("SCM log file (#{path}) cannot be created: #{e.message}") + end + end + @stderr_log_file = writable ? path : false + end + @stderr_log_file || nil end def self.shellout(cmd, options = {}, &block) if logger && logger.debug? logger.debug "Shelling out: #{strip_credential(cmd)}" # Capture stderr in a log file - cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}" + if stderr_log_file + cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}" + end end begin mode = "r+" |