annotate .svn/pristine/39/39e52a0654ea7d5e49b76b29ba4c1190481acad6.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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