annotate .svn/pristine/99/99427a60ba43ee192719046d5e81ce5c2ae0e96f.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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