##// END OF EJS Templates
Check that the SCM log file is writable before using it (#13541)....
Jean-Philippe Lang -
r11468:633e4a00e66d
parent child
Show More
@@ -219,17 +219,38 module Redmine
219 219 end
220 220
221 221 # Path to the file where scm stderr output is logged
222 # Returns nil if the log file is not writable
222 223 def self.stderr_log_file
223 @stderr_log_path ||=
224 Redmine::Configuration['scm_stderr_log_file'].presence ||
225 Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s
224 if @stderr_log_file.nil?
225 writable = false
226 path = Redmine::Configuration['scm_stderr_log_file'].presence
227 path ||= Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s
228 if File.exists?(path)
229 if File.file?(path) && File.writable?(path)
230 writable = true
231 else
232 logger.warn("SCM log file (#{path}) is not writable")
233 end
234 else
235 begin
236 File.open(path, "w") {}
237 writable = true
238 rescue => e
239 logger.warn("SCM log file (#{path}) cannot be created: #{e.message}")
240 end
241 end
242 @stderr_log_file = writable ? path : false
243 end
244 @stderr_log_file || nil
226 245 end
227 246
228 247 def self.shellout(cmd, options = {}, &block)
229 248 if logger && logger.debug?
230 249 logger.debug "Shelling out: #{strip_credential(cmd)}"
231 250 # Capture stderr in a log file
232 cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
251 if stderr_log_file
252 cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
253 end
233 254 end
234 255 begin
235 256 mode = "r+"
General Comments 0
You need to be logged in to leave comments. Login now