annotate .svn/pristine/2f/2f968415d6662b8ce52a48cbeb3f56b87c5a9e9f.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # FileSystem adapter
Chris@1494 5 # File written by Paul Rivier, at Demotera.
Chris@1494 6 #
Chris@1494 7 # This program is free software; you can redistribute it and/or
Chris@1494 8 # modify it under the terms of the GNU General Public License
Chris@1494 9 # as published by the Free Software Foundation; either version 2
Chris@1494 10 # of the License, or (at your option) any later version.
Chris@1494 11 #
Chris@1494 12 # This program is distributed in the hope that it will be useful,
Chris@1494 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 15 # GNU General Public License for more details.
Chris@1494 16 #
Chris@1494 17 # You should have received a copy of the GNU General Public License
Chris@1494 18 # along with this program; if not, write to the Free Software
Chris@1494 19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 20
Chris@1494 21 require 'redmine/scm/adapters/abstract_adapter'
Chris@1494 22 require 'find'
Chris@1494 23
Chris@1494 24 module Redmine
Chris@1494 25 module Scm
Chris@1494 26 module Adapters
Chris@1494 27 class FilesystemAdapter < AbstractAdapter
Chris@1494 28
Chris@1494 29 class << self
Chris@1494 30 def client_available
Chris@1494 31 true
Chris@1494 32 end
Chris@1494 33 end
Chris@1494 34
Chris@1494 35 def initialize(url, root_url=nil, login=nil, password=nil,
Chris@1494 36 path_encoding=nil)
Chris@1494 37 @url = with_trailling_slash(url)
Chris@1494 38 @path_encoding = path_encoding.blank? ? 'UTF-8' : path_encoding
Chris@1494 39 end
Chris@1494 40
Chris@1494 41 def path_encoding
Chris@1494 42 @path_encoding
Chris@1494 43 end
Chris@1494 44
Chris@1494 45 def format_path_ends(path, leading=true, trailling=true)
Chris@1494 46 path = leading ? with_leading_slash(path) :
Chris@1494 47 without_leading_slash(path)
Chris@1494 48 trailling ? with_trailling_slash(path) :
Chris@1494 49 without_trailling_slash(path)
Chris@1494 50 end
Chris@1494 51
Chris@1494 52 def info
Chris@1494 53 info = Info.new({:root_url => target(),
Chris@1494 54 :lastrev => nil
Chris@1494 55 })
Chris@1494 56 info
Chris@1494 57 rescue CommandFailed
Chris@1494 58 return nil
Chris@1494 59 end
Chris@1494 60
Chris@1494 61 def entries(path="", identifier=nil, options={})
Chris@1494 62 entries = Entries.new
Chris@1494 63 trgt_utf8 = target(path)
Chris@1494 64 trgt = scm_iconv(@path_encoding, 'UTF-8', trgt_utf8)
Chris@1494 65 Dir.new(trgt).each do |e1|
Chris@1494 66 e_utf8 = scm_iconv('UTF-8', @path_encoding, e1)
Chris@1494 67 next if e_utf8.blank?
Chris@1494 68 relative_path_utf8 = format_path_ends(
Chris@1494 69 (format_path_ends(path,false,true) + e_utf8),false,false)
Chris@1494 70 t1_utf8 = target(relative_path_utf8)
Chris@1494 71 t1 = scm_iconv(@path_encoding, 'UTF-8', t1_utf8)
Chris@1494 72 relative_path = scm_iconv(@path_encoding, 'UTF-8', relative_path_utf8)
Chris@1494 73 e1 = scm_iconv(@path_encoding, 'UTF-8', e_utf8)
Chris@1494 74 if File.exist?(t1) and # paranoid test
Chris@1494 75 %w{file directory}.include?(File.ftype(t1)) and # avoid special types
Chris@1494 76 not File.basename(e1).match(/^\.+$/) # avoid . and ..
Chris@1494 77 p1 = File.readable?(t1) ? relative_path : ""
Chris@1494 78 utf_8_path = scm_iconv('UTF-8', @path_encoding, p1)
Chris@1494 79 entries <<
Chris@1494 80 Entry.new({ :name => scm_iconv('UTF-8', @path_encoding, File.basename(e1)),
Chris@1494 81 # below : list unreadable files, but dont link them.
Chris@1494 82 :path => utf_8_path,
Chris@1494 83 :kind => (File.directory?(t1) ? 'dir' : 'file'),
Chris@1494 84 :size => (File.directory?(t1) ? nil : [File.size(t1)].pack('l').unpack('L').first),
Chris@1494 85 :lastrev =>
Chris@1494 86 Revision.new({:time => (File.mtime(t1)) })
Chris@1494 87 })
Chris@1494 88 end
Chris@1494 89 end
Chris@1494 90 entries.sort_by_name
Chris@1494 91 rescue => err
Chris@1494 92 logger.error "scm: filesystem: error: #{err.message}"
Chris@1494 93 raise CommandFailed.new(err.message)
Chris@1494 94 end
Chris@1494 95
Chris@1494 96 def cat(path, identifier=nil)
Chris@1494 97 p = scm_iconv(@path_encoding, 'UTF-8', target(path))
Chris@1494 98 File.new(p, "rb").read
Chris@1494 99 rescue => err
Chris@1494 100 logger.error "scm: filesystem: error: #{err.message}"
Chris@1494 101 raise CommandFailed.new(err.message)
Chris@1494 102 end
Chris@1494 103
Chris@1494 104 private
Chris@1494 105
Chris@1494 106 # AbstractAdapter::target is implicitly made to quote paths.
Chris@1494 107 # Here we do not shell-out, so we do not want quotes.
Chris@1494 108 def target(path=nil)
Chris@1494 109 # Prevent the use of ..
Chris@1494 110 if path and !path.match(/(^|\/)\.\.(\/|$)/)
Chris@1494 111 return "#{self.url}#{without_leading_slash(path)}"
Chris@1494 112 end
Chris@1494 113 return self.url
Chris@1494 114 end
Chris@1494 115 end
Chris@1494 116 end
Chris@1494 117 end
Chris@1494 118 end