Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -21,7 +23,8 @@ require 'redmine/scm/adapters'
module Redmine
module Scm
module Adapters
class AbstractAdapter #:nodoc:
# @private
class AbstractAdapter
include Redmine::Utils::Shell
# raised if scm command exited with error, e.g. unknown revision.
@ -175,7 +178,8 @@ module Redmine
(path[-1,1] == "/") ? path[0..-2] : path
end
private
private
def retrieve_root_url
info = self.info
info ? info.root_url : nil
@ -183,7 +187,7 @@ module Redmine
def target(path, sq=true)
path ||= ''
base = path.match(/^\//) ? root_url : url
base = /^\//.match?(path) ? root_url : url
str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
if sq
str = shell_quote(str)
@ -199,10 +203,6 @@ module Redmine
self.class.shellout(cmd, options, &block)
end
def self.logger
Rails.logger
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
@ -211,7 +211,7 @@ module Redmine
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)
if File.file?(path) && File.writable?(path)
writable = true
else
logger.warn("SCM log file (#{path}) is not writable")
@ -228,37 +228,41 @@ module Redmine
end
@stderr_log_file || nil
end
private_class_method :stderr_log_file
def self.shellout(cmd, options = {}, &block)
if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}"
# Capture stderr in a log file
if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
# Singleton class method is public
class << self
def logger
Rails.logger
end
begin
mode = "r+"
IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write unless options[:write_stdin]
block.call(io) if block_given?
def shellout(cmd, options = {}, &block)
if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}"
# Capture stderr in a log file
if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
end
begin
mode = "r+"
IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write unless options[:write_stdin]
yield(io) if block_given?
end
rescue => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end
## If scm command does not exist,
## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
## in production environment.
# rescue Errno::ENOENT => e
rescue Exception => e
msg = strip_credential(e.message)
# The command failed, log it and re-raise
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end
end
@ -267,18 +271,20 @@ module Redmine
q = (Redmine::Platform.mswin? ? '"' : "'")
cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
end
private_class_method :strip_credential
def strip_credential(cmd)
self.class.strip_credential(cmd)
end
def scm_iconv(to, from, str)
return nil if str.nil?
return if str.nil?
return str if to == from && str.encoding.to_s == from
str = str.dup
str.force_encoding(from)
begin
str.encode(to)
rescue Exception => err
rescue => err
logger.error("failed to convert from #{from} to #{to}. #{err}")
nil
end
@ -328,11 +334,11 @@ module Redmine
end
def is_file?
'file' == self.kind
self.kind == 'file'
end
def is_dir?
'dir' == self.kind
self.kind == 'dir'
end
def is_text?