torquebox-vfs 1.0.0.CR1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/gem_hook.rb +18 -0
  2. data/lib/jboss-common-core-2.2.17.GA.jar +0 -0
  3. data/lib/jboss-logging-3.0.0.Beta4.jar +0 -0
  4. data/lib/jboss-logging-spi-2.2.0.CR1.jar +0 -0
  5. data/lib/jboss-logmanager-1.2.0.CR9.jar +0 -0
  6. data/lib/jboss-logmanager-log4j-1.0.0.CR3.jar +0 -0
  7. data/lib/jboss-vfs-3.0.0.GA.jar +0 -0
  8. data/lib/log4j-1.2.14.jar +0 -0
  9. data/lib/org.torquebox.vfs.rb +20 -0
  10. data/lib/torquebox/vfs/debug_filter.rb +37 -0
  11. data/lib/torquebox/vfs/dir.rb +78 -0
  12. data/lib/torquebox/vfs/ext/dir.rb +188 -0
  13. data/lib/torquebox/vfs/ext/file.rb +278 -0
  14. data/lib/torquebox/vfs/ext/file_test.rb +48 -0
  15. data/lib/torquebox/vfs/ext/io.rb +158 -0
  16. data/lib/torquebox/vfs/ext/jdbc.rb +65 -0
  17. data/lib/torquebox/vfs/ext/kernel.rb +30 -0
  18. data/lib/torquebox/vfs/ext/pathname.rb +31 -0
  19. data/lib/torquebox/vfs/ext/tempfile.rb +31 -0
  20. data/lib/torquebox/vfs/ext/vfs.rb +24 -0
  21. data/lib/torquebox/vfs/ext/virtual_file.rb +72 -0
  22. data/lib/torquebox/vfs/file.rb +188 -0
  23. data/lib/torquebox/vfs/glob_filter.rb +46 -0
  24. data/lib/torquebox/vfs/glob_translator.rb +204 -0
  25. data/lib/torquebox/vfs.rb +100 -0
  26. data/lib/torquebox-vfs.jar +0 -0
  27. data/lib/torquebox-vfs.rb +20 -0
  28. data/lib/vfs.rb +20 -0
  29. data/licenses/lgpl-2.1.txt +504 -0
  30. data/spec/dir_spec.rb +259 -0
  31. data/spec/file_spec.rb +451 -0
  32. data/spec/file_test_spec.rb +34 -0
  33. data/spec/io_spec.rb +82 -0
  34. data/spec/jdbc_spec.rb +68 -0
  35. data/spec/pathname_spec.rb +20 -0
  36. data/spec/spec_helper.rb +171 -0
  37. data/spec/vfs_dir_spec.rb +23 -0
  38. data/spec/vfs_spec.rb +36 -0
  39. metadata +121 -0
data/lib/gem_hook.rb ADDED
@@ -0,0 +1,18 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'torquebox/vfs'
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,20 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ # Backwards-compatibility
19
+ $stderr.puts "Usage of 'org.torquebox.vfs' is deprecated. Please use 'torquebox-vfs'."
20
+ require 'torquebox-vfs'
@@ -0,0 +1,37 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'torquebox/vfs/glob_translator'
19
+
20
+
21
+ module TorqueBox
22
+ module VFS
23
+ class DebugFilter
24
+ include Java::org.jboss.vfs.VirtualFileFilter
25
+
26
+ def initialize()
27
+ end
28
+
29
+ def accepts(file)
30
+ puts "visit #{file}"
31
+ true
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,78 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module VFS
20
+ class Dir
21
+ attr_reader :path
22
+ attr_reader :pos
23
+ alias_method :tell, :pos
24
+
25
+ def initialize(path)
26
+ @path = path
27
+ begin
28
+ @virtual_file = org.jboss.vfs.VFS.child( path )
29
+ rescue Java::JavaLang::NullPointerException
30
+ raise Errno::ENOENT.new
31
+ end
32
+ @pos = 0
33
+ @closed = false
34
+ end
35
+
36
+ def close
37
+ @closed = true
38
+ end
39
+
40
+ def each
41
+ @virtual_file.children.each do |child|
42
+ yield child.name
43
+ end
44
+ end
45
+
46
+ def rewind
47
+ @pos = 0
48
+ end
49
+
50
+ def read
51
+ children = @virtual_file.children
52
+ return nil unless ( @pos < children.size )
53
+ child = children[@pos]
54
+ @pos += 1
55
+ child.name
56
+ end
57
+
58
+ def seek(i)
59
+ @pos = i
60
+ self
61
+ end
62
+
63
+ def pos=(i)
64
+ @pos = i
65
+ end
66
+
67
+ def entries
68
+ [ '.', '..' ] + @virtual_file.children.map(&:name)
69
+ end
70
+
71
+ def exists?
72
+ @virtual_file.exists?
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,188 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ class Dir
19
+
20
+ class << self
21
+
22
+ alias_method :open_before_vfs, :open
23
+ alias_method :glob_before_vfs, :glob
24
+ alias_method :mkdir_before_vfs, :mkdir
25
+ alias_method :rmdir_before_vfs, :rmdir
26
+ alias_method :chdir_before_vfs, :chdir
27
+ alias_method :new_before_vfs, :new
28
+ alias_method :entries_before_vfs, :entries
29
+ alias_method :foreach_before_vfs, :foreach
30
+
31
+ # 1.8: open( dirname )
32
+ # 1.9: open( dirname, <, :encoding => enc> )
33
+ # We currently ignore the encoding.
34
+ def open(str, options = nil, &block)
35
+ if ( ::File.exist_without_vfs?( str ) )
36
+ return open_before_vfs(str,&block)
37
+ end
38
+ #puts "open(#{str})"
39
+ result = dir = TorqueBox::VFS::Dir.new( str )
40
+ #puts " result = #{result}"
41
+ unless result.exists?
42
+ return open_before_vfs(str,&block)
43
+ end
44
+ if block
45
+ begin
46
+ result = block.call(dir)
47
+ ensure
48
+ dir.close
49
+ end
50
+ end
51
+ #puts "open(#{str}) return #{result}"
52
+ result
53
+ end
54
+
55
+ def [](pattern)
56
+ self.glob( pattern )
57
+ end
58
+
59
+ def glob(pattern,flags=0, &block)
60
+ is_absolute_vfs = false
61
+
62
+ #str_pattern = "#{pattern}"
63
+ str_pattern = pattern.to_str
64
+ #puts "glob(#{str_pattern})"
65
+
66
+ segments = str_pattern.split( '/' )
67
+
68
+ base_segments = []
69
+ for segment in segments
70
+ if ( segment =~ /[\*\?\[\{\}]/ )
71
+ break
72
+ end
73
+ base_segments << segment
74
+ end
75
+
76
+ base = base_segments.join( '/' )
77
+
78
+ base.gsub!( /\\(.)/, '\1' )
79
+
80
+ #if ( base.empty? || ( ::File.exist_without_vfs?( base ) && ! Java::OrgJbossVirtualPluginsContextJar::JarUtils.isArchive( base ) ) )
81
+ #if ( base.empty? || ( ::File.exist_without_vfs?( base ) ) )
82
+ #puts "doing FS glob"
83
+ #paths = glob_before_vfs( str_pattern, flags, &block )
84
+ #return paths
85
+ #end
86
+
87
+ #puts "base= #{base}"
88
+
89
+ vfs_url, child_path = TorqueBox::VFS.resolve_within_archive( base )
90
+ #puts "vfs_url=#{vfs_url}"
91
+ #puts "child_path=#{child_path}"
92
+
93
+ return [] if vfs_url.nil?
94
+ #puts "segments.size==base_segments.size? #{segments.size == base_segments.size}"
95
+ return [ base ] if segments.size == base_segments.size
96
+
97
+ matcher_segments = segments - base_segments
98
+ matcher = matcher_segments.join( '/' )
99
+ #puts "matcher [#{matcher}]"
100
+
101
+ begin
102
+ #puts "0 vfs_url=#{vfs_url}"
103
+ starting_point = root = org.jboss.vfs::VFS.child( vfs_url )
104
+ #puts "A starting_point=#{starting_point.path_name}"
105
+ starting_point = root.get_child( child_path ) unless ( child_path.nil? || child_path == '' )
106
+ #puts "B starting_point=#{starting_point.path_name}"
107
+ return [] if ( starting_point.nil? || ! starting_point.exists? )
108
+ child_path = starting_point.path_name
109
+ #puts "child- #{child_path}"
110
+ unless ( child_path =~ %r(/$) )
111
+ child_path = "#{child_path}/"
112
+ end
113
+ child_path = "" if child_path == "/"
114
+ #puts "child_path=#{child_path}"
115
+ #puts "base=#{base}"
116
+ filter = TorqueBox::VFS::GlobFilter.new( child_path, matcher )
117
+ #puts "filter is #{filter}"
118
+ paths = starting_point.getChildrenRecursively( filter ).collect{|e|
119
+ #path_name = e.path_name
120
+ path_name = e.getPathNameRelativeTo( starting_point )
121
+ #puts "(collect) path_name=#{path_name}"
122
+ result = ::File.join( base, path_name )
123
+ #puts "(collect) result=#{result}"
124
+ result
125
+ }
126
+ paths.each{|p| block.call(p)} if block
127
+ #puts "Path=#{paths.inspect}"
128
+ paths
129
+ rescue Java::JavaIo::IOException => e
130
+ return []
131
+ end
132
+ end
133
+
134
+ def chdir(*args, &block)
135
+ raise "You shouldn't use chdir, but if you must, pass a block!" unless block_given?
136
+ chdir_before_vfs( *args.map{ |x| File.name_without_vfs(x) }, &block )
137
+ end
138
+
139
+ def rmdir(path)
140
+ name = File.name_without_vfs(path)
141
+ rmdir_before_vfs(name)
142
+ end
143
+ alias_method :unlink, :rmdir
144
+ alias_method :delete, :rmdir
145
+
146
+ def mkdir(path, mode=0777)
147
+ mkdir_before_vfs( File.name_without_vfs(path), mode )
148
+ rescue Errno::ENOTDIR => e
149
+ path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
150
+ mkdir_before_vfs( path, mode )
151
+ rescue Errno::ENOENT => e
152
+ path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
153
+ mkdir_before_vfs( path, mode )
154
+ end
155
+
156
+ # 1.8: new( dirname )
157
+ # 1.9: new( dirname, <, :encoding => enc> )
158
+ # We currently ignore the encoding.
159
+ def new(string, options = nil)
160
+ if ( ::File.exist_without_vfs?( string ) )
161
+ return new_before_vfs( string )
162
+ end
163
+ TorqueBox::VFS::Dir.new( string )
164
+ end
165
+
166
+ # 1.9 has an optional, undocumented options arg that appears to be
167
+ # used for encoding. We'll ignore it for now, since JRuby does as
168
+ # well. (see org.jruby.RubyDir.java)
169
+ def entries(path, options = {})
170
+ if ( ::File.exist_without_vfs?( path ) )
171
+ return entries_before_vfs(path)
172
+ end
173
+ vfs_dir = org.jboss.vfs::VFS.child( File.path_to_str(path) )
174
+ # Delegate to original entries if passed a nonexistent file
175
+ unless vfs_dir.exists?
176
+ return entries_before_vfs( path )
177
+ end
178
+ [ '.', '..' ] + vfs_dir.children.collect{|e| e.name }
179
+ end
180
+
181
+ def foreach(path, &block)
182
+ enum = entries(path).each(&block)
183
+ block_given? ? nil : enum
184
+ end
185
+
186
+ end
187
+ end
188
+
@@ -0,0 +1,278 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ require 'torquebox/vfs/debug_filter'
19
+ require 'torquebox/vfs/ext/tempfile'
20
+
21
+ class File
22
+
23
+ class << self
24
+
25
+ alias_method :open_without_vfs, :open
26
+ alias_method :mtime_without_vfs, :mtime
27
+ alias_method :size_without_vfs, :size
28
+ alias_method :size_without_vfs?, :size?
29
+ alias_method :stat_without_vfs, :stat
30
+ alias_method :lstat_without_vfs, :lstat
31
+ alias_method :exist_without_vfs?, :exist?
32
+ alias_method :directory_without_vfs?, :directory?
33
+ alias_method :dirname_without_vfs, :dirname
34
+ alias_method :file_without_vfs?, :file?
35
+ alias_method :expand_path_without_vfs, :expand_path
36
+ alias_method :unlink_without_vfs, :unlink
37
+ alias_method :readable_without_vfs?, :readable?
38
+ alias_method :chmod_without_vfs, :chmod
39
+ alias_method :chown_without_vfs, :chown
40
+ alias_method :utime_without_vfs, :utime
41
+ alias_method :new_without_vfs, :new
42
+ alias_method :rename_without_vfs, :rename
43
+ alias_method :join_without_vfs, :join
44
+
45
+ def open(fname,mode_str='r', flags=nil, &block)
46
+ if ( Fixnum === fname )
47
+ return open_without_vfs( fname, mode_str, &block )
48
+ end
49
+ unless ( vfs_path?(fname) )
50
+ return open_without_vfs(fname, mode_str, flags, &block )
51
+ end
52
+ if ( File.exist_without_vfs?( name_without_vfs(fname) ) )
53
+ return open_without_vfs( name_without_vfs(fname), mode_str, flags, &block )
54
+ end
55
+ self.vfs_open( fname.to_s, mode_str, &block )
56
+ end
57
+
58
+ def expand_path(*args)
59
+ return args[0].to_s.dup if ( vfs_path?(args[0]) )
60
+ if ( vfs_path?(args[1]) )
61
+ expanded = expand_path_without_vfs(args[0], name_without_vfs(args[1].to_s))
62
+ return TorqueBox::VFS.resolve_path_url(expanded)
63
+ end
64
+ expand_path_without_vfs(*args)
65
+ end
66
+
67
+ def readable?(filename)
68
+ real_name = name_without_vfs( filename )
69
+ return readable_without_vfs?( real_name ) if exist_without_vfs?( real_name )
70
+
71
+ virtual_file = virtual_file( filename )
72
+ # VirtualFile has no readable? so assume we can read it if it exists
73
+ !virtual_file.nil? && virtual_file.exists?
74
+ end
75
+
76
+ def unlink(*file_names)
77
+ file_names.each do |file_name|
78
+ if ( vfs_path?(file_name) )
79
+ virtual_file = org.jboss.vfs::VFS.child( file_name.to_s )
80
+ raise Errno::ENOENT.new(file_name) unless virtual_file.exists()
81
+ virtual_file.delete
82
+ else
83
+ unlink_without_vfs( file_name )
84
+ end
85
+ end
86
+ file_names.size
87
+ end
88
+
89
+ alias_method :delete, :unlink
90
+
91
+ def mtime(filename)
92
+ return mtime_without_vfs(filename) if ( File.exist_without_vfs?( filename ) )
93
+
94
+ vfs_url, child_path = TorqueBox::VFS.resolve_within_archive(filename)
95
+ raise Errno::ENOENT.new(filename) unless vfs_url
96
+
97
+ virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
98
+ virtual_file = virtual_file.get_child( child_path ) if child_path
99
+ raise Errno::ENOENT.new(filename) unless virtual_file.exists?
100
+
101
+ Time.at( virtual_file.getLastModified() / 1000 )
102
+ end
103
+
104
+ def size(filename)
105
+ return size_without_vfs(filename) if ( File.exist_without_vfs?( filename ) )
106
+
107
+
108
+ vfs_url, child_path = TorqueBox::VFS.resolve_within_archive(filename)
109
+ raise Errno::ENOENT.new(filename) unless vfs_url
110
+
111
+ virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
112
+
113
+ raise Errno::ENOENT.new(filename) unless virtual_file.exists
114
+
115
+ virtual_file = virtual_file.get_child( child_path ) if child_path
116
+ raise Errno::ENOENT.new(filename) unless virtual_file.exists
117
+
118
+ virtual_file.size
119
+ end
120
+
121
+ def size?(filename)
122
+ return size_without_vfs?(filename) if ( File.exist_without_vfs?( filename ) )
123
+
124
+ vfs_url, child_path = TorqueBox::VFS.resolve_within_archive(filename)
125
+ return nil unless vfs_url
126
+
127
+ virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
128
+ virtual_file = virtual_file.get_child( child_path ) if child_path
129
+
130
+ return nil unless virtual_file.exists
131
+
132
+ virtual_file.size
133
+ end
134
+
135
+ def stat(filename)
136
+ name = name_without_vfs(filename)
137
+ return stat_without_vfs(name) if ( File.exist_without_vfs?( name ) )
138
+
139
+ vfs_url, child_path = TorqueBox::VFS.resolve_within_archive(filename)
140
+ raise Errno::ENOENT.new(filename) unless vfs_url
141
+
142
+ virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
143
+ virtual_file = virtual_file.get_child( child_path ) if child_path
144
+ raise Errno::ENOENT.new(filename) unless virtual_file.exists?
145
+
146
+ TorqueBox::VFS::File::Stat.new( virtual_file )
147
+ end
148
+
149
+ def lstat(filename)
150
+ name = name_without_vfs(filename)
151
+ return lstat_without_vfs(name) if ( File.exist_without_vfs?( name ) )
152
+ stat(filename)
153
+ end
154
+
155
+ def rename(oldname, newname)
156
+ rename_without_vfs( name_without_vfs(oldname), name_without_vfs(newname) )
157
+ end
158
+
159
+ def exist?(filename)
160
+ return true if exist_without_vfs?( filename )
161
+
162
+ virtual_file = virtual_file(filename)
163
+ !virtual_file.nil? && virtual_file.exists?
164
+ end
165
+ alias_method :exists?, :exist?
166
+
167
+ def writable?(filename)
168
+ stat = stat(filename)
169
+ return stat.writable? if stat
170
+ false
171
+ rescue Errno::ENOENT
172
+ false
173
+ end
174
+
175
+ def directory?(filename)
176
+ return directory_without_vfs?( filename ) if exist_without_vfs?( filename )
177
+
178
+ virtual_file = virtual_file(filename)
179
+ !virtual_file.nil? && virtual_file.is_directory?
180
+ end
181
+
182
+ def file?(filename)
183
+ return true if file_without_vfs?( filename )
184
+
185
+ virtual_file = virtual_file(filename)
186
+ !virtual_file.nil? && virtual_file.is_leaf?
187
+ end
188
+
189
+ def dirname(filename)
190
+ dirname = dirname_without_vfs(name_without_vfs(filename))
191
+ vfs_path?(filename) ? TorqueBox::VFS.resolve_path_url(dirname) : dirname
192
+ end
193
+
194
+ def join(*args)
195
+ prefix = vfs_path?(args[0]) ? "vfs:" : ""
196
+ args = args.map do |arg|
197
+ if arg.is_a?(Array)
198
+ raise ArgumentError if arg.include?(arg)
199
+ join(*arg)
200
+ else
201
+ arg
202
+ end
203
+ end
204
+ prefix + join_without_vfs(*args.map{|x|name_without_vfs(x)})
205
+ end
206
+
207
+ def new(*args, &block)
208
+ fname = args.size > 0 ? args[0] : nil
209
+ if ( Fixnum === fname )
210
+ return new_without_vfs( *args, &block )
211
+ end
212
+ unless ( vfs_path?(fname) )
213
+ return new_without_vfs( *args, &block )
214
+ end
215
+ if ( File.exist_without_vfs?( name_without_vfs(fname) ) )
216
+ args[0] = name_without_vfs(fname)
217
+ return new_without_vfs( *args, &block )
218
+ end
219
+ # File.new doesn't pass a block through to the opened file
220
+ IO.vfs_open( *args )
221
+ end
222
+
223
+ def chmod(mode_int, *files)
224
+ writable_operation(*files) do |filename|
225
+ chmod_without_vfs( mode_int, filename )
226
+ end
227
+ end
228
+
229
+ def chown(owner, group, *files)
230
+ writable_operation(*files) do |filename|
231
+ chown_without_vfs( owner, group, filename )
232
+ end
233
+ end
234
+
235
+ def utime(accesstime, modtime, *files)
236
+ writable_operation(*files) do |filename|
237
+ utime_without_vfs( accesstime, modtime, filename )
238
+ end
239
+ end
240
+
241
+ def writable_operation(*files)
242
+ files.each do |name|
243
+ begin
244
+ yield name_without_vfs(name)
245
+ rescue Errno::ENOENT => e
246
+ yield TorqueBox::VFS.writable_path_or_error( name, e )
247
+ end
248
+ end
249
+ files.size
250
+ end
251
+
252
+ def name_without_vfs(filename)
253
+ name = path_to_str(filename).gsub("\\", "/")
254
+ if vfs_path?(name)
255
+ result = name[4..-1]
256
+ result.size==0 ? "/" : result
257
+ else
258
+ name
259
+ end
260
+ end
261
+
262
+ def path_to_str(path)
263
+ # 1.9 - to_str became to_path for Pathnames
264
+ return path.to_path if path.respond_to?(:to_path)
265
+ raise TypeError unless path.respond_to?(:to_str)
266
+ path.to_str
267
+ end
268
+
269
+ def vfs_path?(path)
270
+ path.to_s =~ /^vfs:/
271
+ end
272
+
273
+ def virtual_file(filename)
274
+ TorqueBox::VFS.virtual_file(filename)
275
+ end
276
+ end
277
+
278
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module FileTest
19
+
20
+ class << self
21
+
22
+ def directory?(filename)
23
+ File.directory?(filename)
24
+ end
25
+
26
+ def exist?(filename)
27
+ File.exist?(filename)
28
+ end
29
+
30
+ def exists?(filename)
31
+ File.exists?(filename)
32
+ end
33
+
34
+ def file?(filename)
35
+ File.file?(filename)
36
+ end
37
+
38
+ def readable?(filename)
39
+ File.readable?(filename)
40
+ end
41
+
42
+ def writable?(filename)
43
+ File.writable?(filename)
44
+ end
45
+
46
+ end
47
+
48
+ end