comparison lib/redmine/scm/adapters/.svn/text-base/filesystem_adapter.rb.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children 051f544170fe
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # FileSystem adapter
5 # File written by Paul Rivier, at Demotera.
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 require 'redmine/scm/adapters/abstract_adapter'
22 require 'find'
23
24 module Redmine
25 module Scm
26 module Adapters
27 class FilesystemAdapter < AbstractAdapter
28
29
30 def initialize(url, root_url=nil, login=nil, password=nil)
31 @url = with_trailling_slash(url)
32 end
33
34 def format_path_ends(path, leading=true, trailling=true)
35 path = leading ? with_leading_slash(path) :
36 without_leading_slash(path)
37 trailling ? with_trailling_slash(path) :
38 without_trailling_slash(path)
39 end
40
41 def info
42 info = Info.new({:root_url => target(),
43 :lastrev => nil
44 })
45 info
46 rescue CommandFailed
47 return nil
48 end
49
50 def entries(path="", identifier=nil)
51 entries = Entries.new
52 Dir.new(target(path)).each do |e|
53 relative_path = format_path_ends((format_path_ends(path,
54 false,
55 true) + e),
56 false,false)
57 target = target(relative_path)
58 entries <<
59 Entry.new({ :name => File.basename(e),
60 # below : list unreadable files, but dont link them.
61 :path => File.readable?(target) ? relative_path : "",
62 :kind => (File.directory?(target) ? 'dir' : 'file'),
63 :size => (File.directory?(target) ? nil : [File.size(target)].pack('l').unpack('L').first),
64 :lastrev =>
65 Revision.new({:time => (File.mtime(target)).localtime,
66 })
67 }) if File.exist?(target) and # paranoid test
68 %w{file directory}.include?(File.ftype(target)) and # avoid special types
69 not File.basename(e).match(/^\.+$/) # avoid . and ..
70 end
71 entries.sort_by_name
72 end
73
74 def cat(path, identifier=nil)
75 File.new(target(path), "rb").read
76 end
77
78 private
79
80 # AbstractAdapter::target is implicitly made to quote paths.
81 # Here we do not shell-out, so we do not want quotes.
82 def target(path=nil)
83 #Prevent the use of ..
84 if path and !path.match(/(^|\/)\.\.(\/|$)/)
85 return "#{self.url}#{without_leading_slash(path)}"
86 end
87 return self.url
88 end
89
90 end
91 end
92 end
93 end