##// END OF EJS Templates
Changes RedMine to Redmine in copyright notices....
Changes RedMine to Redmine in copyright notices. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9637 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r9454:e876d1bfc014
r9454:e876d1bfc014
Show More
filesystem_adapter.rb
118 lines | 4.3 KiB | text/x-ruby | RubyLexer
/ lib / redmine / scm / adapters / filesystem_adapter.rb
Jean-Philippe Lang
Changes RedMine to Redmine in copyright notices....
r9454 # Redmine - project management software
Jean-Philippe Lang
Copyright update....
r9453 # Copyright (C) 2006-2012 Jean-Philippe Lang
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 #
# FileSystem adapter
# File written by Paul Rivier, at Demotera.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
scm: filesystem: remove trailing white-spaces from adapter source....
r5550 #
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
scm: filesystem: remove trailing white-spaces from adapter source....
r5550 #
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'redmine/scm/adapters/abstract_adapter'
require 'find'
module Redmine
module Scm
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 module Adapters
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 class FilesystemAdapter < AbstractAdapter
Toshi MARUYAMA
scm: use shell quote for scm command at adapter level (#7517, #4273)....
r4701
class << self
def client_available
true
end
end
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494
Toshi MARUYAMA
scm: update adapter initialize() to use path encoding (#2664, #2274)....
r4821 def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil)
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 @url = with_trailling_slash(url)
Toshi MARUYAMA
scm: filesystem: fix loss non ASCII paths if path_encoding is '' (#2274)....
r5509 @path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 end
Toshi MARUYAMA
scm: filesystem: override "path_encoding" method in adapter (#2274)....
r5744 def path_encoding
@path_encoding
end
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 def format_path_ends(path, leading=true, trailling=true)
Toshi MARUYAMA
scm: filesystem: remove trailing white-spaces from adapter source....
r5550 path = leading ? with_leading_slash(path) :
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 without_leading_slash(path)
Toshi MARUYAMA
scm: filesystem: remove trailing white-spaces from adapter source....
r5550 trailling ? with_trailling_slash(path) :
without_trailling_slash(path)
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 end
def info
info = Info.new({:root_url => target(),
:lastrev => nil
})
info
rescue CommandFailed
return nil
end
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787
Toshi MARUYAMA
scm: add "options" parameter in adapter entries()....
r5518 def entries(path="", identifier=nil, options={})
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 entries = Entries.new
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 trgt_utf8 = target(path)
trgt = scm_iconv(@path_encoding, 'UTF-8', trgt_utf8)
Dir.new(trgt).each do |e1|
e_utf8 = scm_iconv('UTF-8', @path_encoding, e1)
Toshi MARUYAMA
scm: filesystem: remove trailing white-spaces from adapter source....
r5550 next if e_utf8.blank?
Toshi MARUYAMA
scm: filesystem: prevent exception raises if path encoding is incorrect....
r5053 relative_path_utf8 = format_path_ends(
(format_path_ends(path,false,true) + e_utf8),false,false)
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 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 <<
Entry.new({ :name => scm_iconv('UTF-8', @path_encoding, File.basename(e1)),
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 # below : list unreadable files, but dont link them.
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 :path => utf_8_path,
:kind => (File.directory?(t1) ? 'dir' : 'file'),
:size => (File.directory?(t1) ? nil : [File.size(t1)].pack('l').unpack('L').first),
Toshi MARUYAMA
scm: filesystem: remove trailing white-spaces from adapter source....
r5550 :lastrev =>
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 Revision.new({:time => (File.mtime(t1)) })
})
end
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 end
entries.sort_by_name
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 rescue => err
logger.error "scm: filesystem: error: #{err.message}"
raise CommandFailed.new(err.message)
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 end
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 def cat(path, identifier=nil)
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 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)
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 end
private
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 # AbstractAdapter::target is implicitly made to quote paths.
# Here we do not shell-out, so we do not want quotes.
def target(path=nil)
Toshi MARUYAMA
scm: filesystem: refactor for path encoding (#2274)....
r4787 # Prevent the use of ..
Jean-Philippe Lang
Adds Filesystem adapter (patch #1393 by Paul R)....
r1494 if path and !path.match(/(^|\/)\.\.(\/|$)/)
return "#{self.url}#{without_leading_slash(path)}"
end
return self.url
end
end
end
end
end