scm: filesystem: refactor for path encoding (#2274).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4907 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8963579be3
commit
a189b4b377
@ -34,6 +34,7 @@ module Redmine
|
|||||||
|
|
||||||
def initialize(url, root_url=nil, login=nil, password=nil)
|
def initialize(url, root_url=nil, login=nil, password=nil)
|
||||||
@url = with_trailling_slash(url)
|
@url = with_trailling_slash(url)
|
||||||
|
@path_encoding = 'UTF-8'
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_path_ends(path, leading=true, trailling=true)
|
def format_path_ends(path, leading=true, trailling=true)
|
||||||
@ -54,30 +55,43 @@ module Redmine
|
|||||||
|
|
||||||
def entries(path="", identifier=nil)
|
def entries(path="", identifier=nil)
|
||||||
entries = Entries.new
|
entries = Entries.new
|
||||||
Dir.new(target(path)).each do |e|
|
trgt_utf8 = target(path)
|
||||||
relative_path = format_path_ends((format_path_ends(path,
|
trgt = scm_iconv(@path_encoding, 'UTF-8', trgt_utf8)
|
||||||
false,
|
Dir.new(trgt).each do |e1|
|
||||||
true) + e),
|
e_utf8 = scm_iconv('UTF-8', @path_encoding, e1)
|
||||||
false,false)
|
relative_path_utf8 = format_path_ends((format_path_ends(path,false,true) + e_utf8),false,false)
|
||||||
target = target(relative_path)
|
t1_utf8 = target(relative_path_utf8)
|
||||||
|
t1 = scm_iconv(@path_encoding, 'UTF-8', t1_utf8)
|
||||||
|
relative_path = scm_iconv(@path_encoding, 'UTF-8', relative_path_utf8)
|
||||||
|
e1 = scm_iconv(@path_encoding, 'UTF-8', e_utf8)
|
||||||
|
if File.exist?(t1) and # paranoid test
|
||||||
|
%w{file directory}.include?(File.ftype(t1)) and # avoid special types
|
||||||
|
not File.basename(e1).match(/^\.+$/) # avoid . and ..
|
||||||
|
p1 = File.readable?(t1) ? relative_path : ""
|
||||||
|
utf_8_path = scm_iconv('UTF-8', @path_encoding, p1)
|
||||||
entries <<
|
entries <<
|
||||||
Entry.new({ :name => File.basename(e),
|
Entry.new({ :name => scm_iconv('UTF-8', @path_encoding, File.basename(e1)),
|
||||||
# below : list unreadable files, but dont link them.
|
# below : list unreadable files, but dont link them.
|
||||||
:path => File.readable?(target) ? relative_path : "",
|
:path => utf_8_path,
|
||||||
:kind => (File.directory?(target) ? 'dir' : 'file'),
|
:kind => (File.directory?(t1) ? 'dir' : 'file'),
|
||||||
:size => (File.directory?(target) ? nil : [File.size(target)].pack('l').unpack('L').first),
|
:size => (File.directory?(t1) ? nil : [File.size(t1)].pack('l').unpack('L').first),
|
||||||
:lastrev =>
|
:lastrev =>
|
||||||
Revision.new({:time => (File.mtime(target)).localtime,
|
Revision.new({:time => (File.mtime(t1)) })
|
||||||
})
|
})
|
||||||
}) if File.exist?(target) and # paranoid test
|
end
|
||||||
%w{file directory}.include?(File.ftype(target)) and # avoid special types
|
|
||||||
not File.basename(e).match(/^\.+$/) # avoid . and ..
|
|
||||||
end
|
end
|
||||||
entries.sort_by_name
|
entries.sort_by_name
|
||||||
|
rescue => err
|
||||||
|
logger.error "scm: filesystem: error: #{err.message}"
|
||||||
|
raise CommandFailed.new(err.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cat(path, identifier=nil)
|
def cat(path, identifier=nil)
|
||||||
File.new(target(path), "rb").read
|
p = scm_iconv(@path_encoding, 'UTF-8', target(path))
|
||||||
|
File.new(p, "rb").read
|
||||||
|
rescue => err
|
||||||
|
logger.error "scm: filesystem: error: #{err.message}"
|
||||||
|
raise CommandFailed.new(err.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -85,13 +99,12 @@ module Redmine
|
|||||||
# AbstractAdapter::target is implicitly made to quote paths.
|
# AbstractAdapter::target is implicitly made to quote paths.
|
||||||
# Here we do not shell-out, so we do not want quotes.
|
# Here we do not shell-out, so we do not want quotes.
|
||||||
def target(path=nil)
|
def target(path=nil)
|
||||||
#Prevent the use of ..
|
# Prevent the use of ..
|
||||||
if path and !path.match(/(^|\/)\.\.(\/|$)/)
|
if path and !path.match(/(^|\/)\.\.(\/|$)/)
|
||||||
return "#{self.url}#{without_leading_slash(path)}"
|
return "#{self.url}#{without_leading_slash(path)}"
|
||||||
end
|
end
|
||||||
return self.url
|
return self.url
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user