org.torquebox.vfs 1.0.0.Beta22 → 1.0.0.Beta23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vfs/dir.rb +7 -3
- data/lib/vfs/ext/dir.rb +15 -4
- data/lib/vfs/ext/file.rb +58 -39
- data/lib/vfs/ext/file_test.rb +32 -0
- data/lib/vfs/ext/io.rb +7 -4
- data/lib/vfs/ext/jdbc.rb +23 -0
- data/lib/vfs/ext/pathname.rb +14 -0
- data/lib/vfs/ext/vfs.rb +1 -1
- data/lib/vfs/file.rb +1 -1
- data/lib/vfs/glob_filter.rb +14 -7
- data/lib/vfs.rb +33 -3
- data/spec/dir_spec.rb +59 -7
- data/spec/file_spec.rb +116 -15
- data/spec/file_test_spec.rb +34 -0
- data/spec/pathname_spec.rb +20 -0
- data/spec/vfs_dir_spec.rb +32 -0
- data/spec/vfs_spec.rb +22 -11
- metadata +12 -3
data/lib/vfs/dir.rb
CHANGED
@@ -10,7 +10,7 @@ module VFS
|
|
10
10
|
@path = path
|
11
11
|
begin
|
12
12
|
@virtual_file = org.jboss.vfs.VFS.child( path )
|
13
|
-
rescue Java::JavaLang::NullPointerException
|
13
|
+
rescue Java::JavaLang::NullPointerException
|
14
14
|
raise Errno::ENOENT.new
|
15
15
|
end
|
16
16
|
@pos = 0
|
@@ -38,7 +38,7 @@ module VFS
|
|
38
38
|
@pos += 1
|
39
39
|
child.name
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def seek(i)
|
43
43
|
@pos = i
|
44
44
|
self
|
@@ -48,7 +48,11 @@ module VFS
|
|
48
48
|
@pos = i
|
49
49
|
end
|
50
50
|
|
51
|
+
def entries
|
52
|
+
@virtual_file.children.map(&:name)
|
53
|
+
end
|
54
|
+
|
51
55
|
end
|
52
56
|
|
53
|
-
end
|
57
|
+
end
|
54
58
|
|
data/lib/vfs/ext/dir.rb
CHANGED
@@ -6,6 +6,7 @@ class Dir
|
|
6
6
|
alias_method :open_before_vfs, :open
|
7
7
|
alias_method :glob_before_vfs, :glob
|
8
8
|
alias_method :mkdir_before_vfs, :mkdir
|
9
|
+
alias_method :new_before_vfs, :new
|
9
10
|
|
10
11
|
def open(str,&block)
|
11
12
|
#if ( ::File.exist_without_vfs?( str.to_str ) && ! Java::OrgJbossVirtualPluginsContextJar::JarUtils.isArchive( str.to_str ) )
|
@@ -19,7 +20,7 @@ class Dir
|
|
19
20
|
begin
|
20
21
|
result = block.call(dir)
|
21
22
|
ensure
|
22
|
-
dir.close
|
23
|
+
dir.close
|
23
24
|
end
|
24
25
|
end
|
25
26
|
#puts "open(#{str}) return #{result}"
|
@@ -58,7 +59,7 @@ class Dir
|
|
58
59
|
#end
|
59
60
|
|
60
61
|
#puts "base= #{base}"
|
61
|
-
|
62
|
+
|
62
63
|
vfs_url, child_path = VFS.resolve_within_archive( base )
|
63
64
|
#puts "vfs_url=#{vfs_url}"
|
64
65
|
#puts "child_path=#{child_path}"
|
@@ -88,7 +89,7 @@ class Dir
|
|
88
89
|
#puts "base=#{base}"
|
89
90
|
filter = VFS::GlobFilter.new( child_path, matcher )
|
90
91
|
#puts "filter is #{filter}"
|
91
|
-
paths = starting_point.getChildrenRecursively( filter ).collect{|e|
|
92
|
+
paths = starting_point.getChildrenRecursively( filter ).collect{|e|
|
92
93
|
#path_name = e.path_name
|
93
94
|
path_name = e.getPathNameRelativeTo( starting_point )
|
94
95
|
#puts "(collect) path_name=#{path_name}"
|
@@ -107,7 +108,17 @@ class Dir
|
|
107
108
|
def mkdir(path, mode=0777)
|
108
109
|
real_path = path =~ /^vfs:/ ? path[4..-1] : path
|
109
110
|
mkdir_before_vfs( real_path, mode )
|
111
|
+
rescue Errno::ENOTDIR => e
|
112
|
+
path = VFS.writable_path_or_error( path, e )
|
113
|
+
mkdir_before_vfs( path, mode )
|
114
|
+
end
|
115
|
+
|
116
|
+
def new(string)
|
117
|
+
if ( ::File.exist_without_vfs?( string.to_s ) )
|
118
|
+
return new_before_vfs( string )
|
119
|
+
end
|
120
|
+
VFS::Dir.new( string.to_s )
|
110
121
|
end
|
111
122
|
end
|
112
|
-
end
|
123
|
+
end
|
113
124
|
|
data/lib/vfs/ext/file.rb
CHANGED
@@ -6,6 +6,8 @@ class File
|
|
6
6
|
|
7
7
|
alias_method :open_without_vfs, :open
|
8
8
|
alias_method :mtime_without_vfs, :mtime
|
9
|
+
alias_method :size_without_vfs, :size
|
10
|
+
alias_method :size_without_vfs?, :size?
|
9
11
|
alias_method :stat_without_vfs, :stat
|
10
12
|
alias_method :exist_without_vfs?, :exist?
|
11
13
|
alias_method :directory_without_vfs?, :directory?
|
@@ -31,15 +33,20 @@ class File
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def expand_path(*args)
|
36
|
+
return args[0].to_s.dup if ( vfs_path?(args[0]) )
|
34
37
|
if ( vfs_path?(args[1]) )
|
35
|
-
|
38
|
+
expanded = expand_path_without_vfs(args[0], name_without_vfs(args[1].to_s))
|
39
|
+
return VFS.resolve_path_url(expanded)
|
36
40
|
end
|
37
|
-
return args[0].to_s.dup if ( vfs_path?(args[0]) )
|
38
41
|
expand_path_without_vfs(*args)
|
39
42
|
end
|
40
43
|
|
41
44
|
def readable?(filename)
|
42
|
-
readable_without_vfs? name_without_vfs(filename)
|
45
|
+
return true if readable_without_vfs?( name_without_vfs( filename ) )
|
46
|
+
|
47
|
+
virtual_file = virtual_file( filename )
|
48
|
+
# VirtualFile has no readable? so assume we can read it if it exists
|
49
|
+
!virtual_file.nil? && virtual_file.exists?
|
43
50
|
end
|
44
51
|
|
45
52
|
def unlink(*file_names)
|
@@ -69,6 +76,35 @@ class File
|
|
69
76
|
Time.at( virtual_file.getLastModified() / 1000 )
|
70
77
|
end
|
71
78
|
|
79
|
+
def size(filename)
|
80
|
+
return size_without_vfs(filename) if ( File.exist_without_vfs?( filename ) )
|
81
|
+
|
82
|
+
vfs_url, child_path = VFS.resolve_within_archive(filename)
|
83
|
+
raise Errno::ENOENT.new unless vfs_url
|
84
|
+
|
85
|
+
virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
|
86
|
+
virtual_file = virtual_file.get_child( child_path ) if child_path
|
87
|
+
|
88
|
+
raise Errno::ENOENT.new unless virtual_file.exists
|
89
|
+
|
90
|
+
virtual_file.size
|
91
|
+
end
|
92
|
+
|
93
|
+
def size?(filename)
|
94
|
+
return size_without_vfs?(filename) if ( File.exist_without_vfs?( filename ) )
|
95
|
+
|
96
|
+
vfs_url, child_path = VFS.resolve_within_archive(filename)
|
97
|
+
return nil unless vfs_url
|
98
|
+
|
99
|
+
virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
|
100
|
+
virtual_file = virtual_file.get_child( child_path ) if child_path
|
101
|
+
|
102
|
+
return nil unless virtual_file.exists
|
103
|
+
|
104
|
+
virtual_file.size
|
105
|
+
end
|
106
|
+
|
107
|
+
|
72
108
|
def stat(filename)
|
73
109
|
return stat_without_vfs(filename) if ( File.exist_without_vfs?( filename ) )
|
74
110
|
|
@@ -88,17 +124,8 @@ class File
|
|
88
124
|
def exist?(filename)
|
89
125
|
return true if exist_without_vfs?( filename )
|
90
126
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
begin
|
95
|
-
virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
|
96
|
-
virtual_file = virtual_file.get_child( child_path ) if child_path
|
97
|
-
|
98
|
-
return ( ( ! virtual_file.nil? ) && virtual_file.exists() )
|
99
|
-
rescue Java::JavaIo::IOException => e
|
100
|
-
return false
|
101
|
-
end
|
127
|
+
virtual_file = virtual_file(filename)
|
128
|
+
!virtual_file.nil? && virtual_file.exists?
|
102
129
|
end
|
103
130
|
|
104
131
|
def writable?(filename)
|
@@ -110,38 +137,25 @@ class File
|
|
110
137
|
def directory?(filename)
|
111
138
|
return true if directory_without_vfs?( filename )
|
112
139
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
begin
|
117
|
-
virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
|
118
|
-
virtual_file = virtual_file.get_child( child_path ) if child_path
|
119
|
-
|
120
|
-
return ( ( ! virtual_file.nil? ) && ( virtual_file.isDirectory() ) )
|
121
|
-
rescue Java::JavaIo::IOException => e
|
122
|
-
return false
|
123
|
-
end
|
140
|
+
virtual_file = virtual_file(filename)
|
141
|
+
!virtual_file.nil? && virtual_file.is_directory?
|
124
142
|
end
|
125
143
|
|
126
144
|
def file?(filename)
|
127
145
|
return true if file_without_vfs?( filename )
|
128
146
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
begin
|
133
|
-
virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
|
134
|
-
virtual_file = virtual_file.get_child( child_path ) if child_path
|
135
|
-
|
136
|
-
return ( ( ! virtual_file.nil? ) && ( virtual_file.isLeaf() ) )
|
137
|
-
rescue Java::JavaIo::IOException => e
|
138
|
-
return false
|
139
|
-
end
|
147
|
+
virtual_file = virtual_file(filename)
|
148
|
+
!virtual_file.nil? && virtual_file.is_leaf?
|
140
149
|
end
|
141
150
|
|
142
151
|
def chmod(mode_int, *files)
|
143
152
|
files.each do |name|
|
144
|
-
|
153
|
+
begin
|
154
|
+
chmod_without_vfs( mode_int, name_without_vfs(name) )
|
155
|
+
rescue Errno::ENOENT => e
|
156
|
+
name = VFS.writable_path_or_error( name, e )
|
157
|
+
chmod_without_vfs( mode_int, name )
|
158
|
+
end
|
145
159
|
end
|
146
160
|
end
|
147
161
|
|
@@ -163,16 +177,21 @@ class File
|
|
163
177
|
|
164
178
|
def dirname(filename)
|
165
179
|
dirname = dirname_without_vfs(name_without_vfs(filename))
|
166
|
-
vfs_path?(filename) ?
|
180
|
+
vfs_path?(filename) ? VFS.resolve_path_url(dirname) : dirname
|
167
181
|
end
|
168
182
|
|
169
183
|
def name_without_vfs(filename)
|
170
|
-
|
184
|
+
name = filename.to_s.gsub("\\", "/")
|
185
|
+
vfs_path?(name) ? name[4..-1] : name
|
171
186
|
end
|
172
187
|
|
173
188
|
def vfs_path?(path)
|
174
189
|
path.to_s =~ /^vfs:/
|
175
190
|
end
|
191
|
+
|
192
|
+
def virtual_file(filename)
|
193
|
+
VFS.virtual_file(filename)
|
194
|
+
end
|
176
195
|
end
|
177
196
|
|
178
197
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
module FileTest
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def directory?(filename)
|
7
|
+
File.directory?(filename)
|
8
|
+
end
|
9
|
+
|
10
|
+
def exist?(filename)
|
11
|
+
File.exist?(filename)
|
12
|
+
end
|
13
|
+
|
14
|
+
def exists?(filename)
|
15
|
+
File.exists?(filename)
|
16
|
+
end
|
17
|
+
|
18
|
+
def file?(filename)
|
19
|
+
File.file?(filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
def readable?(filename)
|
23
|
+
File.readable?(filename)
|
24
|
+
end
|
25
|
+
|
26
|
+
def writable?(filename)
|
27
|
+
File.writable?(filename)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/vfs/ext/io.rb
CHANGED
@@ -69,6 +69,9 @@ class IO
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
# VFS doesn't correctly handle relative paths when
|
73
|
+
# retrieving the physical file so expand it
|
74
|
+
fd = File.expand_path( fd )
|
72
75
|
virtual_file = org.jboss.vfs.VFS.child( fd )
|
73
76
|
|
74
77
|
if ( ! create && ! virtual_file.exists )
|
@@ -83,9 +86,9 @@ class IO
|
|
83
86
|
java_out = java.io::FileOutputStream.new( physical_file, append )
|
84
87
|
ruby_io = java_out.to_io
|
85
88
|
elsif ( read && write )
|
86
|
-
raise Error.new( "Random-access on VFS not supported" )
|
89
|
+
raise Error.new( "Random-access on VFS not supported" )
|
87
90
|
end
|
88
|
-
|
91
|
+
|
89
92
|
if ( block )
|
90
93
|
begin
|
91
94
|
block.call( ruby_io )
|
@@ -101,7 +104,7 @@ class IO
|
|
101
104
|
def read(name, length=nil, offset=nil)
|
102
105
|
return read_without_vfs(name, length, offset) if ::File.exist_without_vfs?( name )
|
103
106
|
|
104
|
-
if ( name =~ /^\// || name =~ /^vfs:\// )
|
107
|
+
if ( name =~ /^\// || name =~ /^vfs:\// )
|
105
108
|
full_path = name
|
106
109
|
else
|
107
110
|
full_path = File.join( Dir.pwd, name )
|
@@ -110,7 +113,7 @@ class IO
|
|
110
113
|
raise ::Errno::ENOENT.new( "#{name} (#{virtual_file})" ) unless virtual_file.exists()
|
111
114
|
|
112
115
|
stream = virtual_file.openStream()
|
113
|
-
io = stream.to_io
|
116
|
+
io = stream.to_io
|
114
117
|
begin
|
115
118
|
s = io.read
|
116
119
|
ensure
|
data/lib/vfs/ext/jdbc.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Java::java.sql::DriverManager
|
2
|
+
class << self
|
3
|
+
alias_method :get_connection_without_vfs, :getConnection
|
4
|
+
alias_method :register_driver_without_vfs, :registerDriver
|
5
|
+
|
6
|
+
def getConnection(url, user, pass)
|
7
|
+
url = url.sub(':vfs:', ':')
|
8
|
+
get_connection_without_vfs(url, user, pass)
|
9
|
+
rescue => e
|
10
|
+
# If we didn't register a driver, throw the exception
|
11
|
+
raise e unless @driver
|
12
|
+
# If we did register a driver, try to connection using it directly
|
13
|
+
props = java.util.Properties.new
|
14
|
+
props.setProperty("user", user)
|
15
|
+
props.setProperty("password", pass)
|
16
|
+
@driver.connect(url, props)
|
17
|
+
end
|
18
|
+
|
19
|
+
def registerDriver(driver)
|
20
|
+
@driver = driver
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/vfs/ext/vfs.rb
CHANGED
data/lib/vfs/file.rb
CHANGED
data/lib/vfs/glob_filter.rb
CHANGED
@@ -5,7 +5,6 @@ module VFS
|
|
5
5
|
include Java::org.jboss.vfs.VirtualFileFilter
|
6
6
|
|
7
7
|
def initialize(child_path, glob)
|
8
|
-
#puts "init #{child_path} #{glob}"
|
9
8
|
@child_path = child_path
|
10
9
|
glob_segments = glob.split( '/' )
|
11
10
|
regexp_segments = []
|
@@ -14,7 +13,14 @@ module VFS
|
|
14
13
|
if ( gs == '**' )
|
15
14
|
regexp_segments << '(.*)'
|
16
15
|
else
|
17
|
-
gs.gsub!(
|
16
|
+
gs.gsub!( /\./, '\.')
|
17
|
+
gs.gsub!( /\*/ ) do |m|
|
18
|
+
if ( $` == '' )
|
19
|
+
'([^\/\.][^\/]*)?'
|
20
|
+
else
|
21
|
+
'[^\/]*'
|
22
|
+
end
|
23
|
+
end
|
18
24
|
gs.gsub!( /\?/, '.')
|
19
25
|
gs.gsub!( /\{[^\}]+\}/ ) do |m|
|
20
26
|
options = m[1..-2].split(',', -1)
|
@@ -29,20 +35,21 @@ module VFS
|
|
29
35
|
end
|
30
36
|
|
31
37
|
regexp_str = regexp_segments.join
|
32
|
-
#puts "regexp_str(1) [#{regexp_str}]"
|
33
38
|
if ( @child_path && @child_path != '' )
|
34
|
-
regexp_str = ::File.join( "^#{@child_path}", "#{regexp_str}$" )
|
39
|
+
#regexp_str = ::File.join( "^#{@child_path}", "#{regexp_str}$" )
|
40
|
+
if ( @child_path[-1,1] == '/' )
|
41
|
+
regexp_str = "^#{@child_path}#{regexp_str}$"
|
42
|
+
else
|
43
|
+
regexp_str = "^#{@child_path}/#{regexp_str}$"
|
44
|
+
end
|
35
45
|
else
|
36
46
|
regexp_str = "^#{regexp_str}$"
|
37
47
|
end
|
38
|
-
#puts "regexp_str(2) [#{regexp_str}]"
|
39
48
|
@regexp = Regexp.new( regexp_str )
|
40
49
|
end
|
41
50
|
|
42
51
|
def accepts(file)
|
43
|
-
#puts "accepts(#{file.path_name}) vs #{@regexp}"
|
44
52
|
acceptable = ( !!( file.path_name =~ @regexp ) )
|
45
|
-
#puts " -> #{acceptable}"
|
46
53
|
!!( file.path_name =~ @regexp )
|
47
54
|
end
|
48
55
|
end
|
data/lib/vfs.rb
CHANGED
@@ -10,18 +10,21 @@ require 'vfs/glob_filter'
|
|
10
10
|
require 'vfs/ext/vfs'
|
11
11
|
require 'vfs/ext/io'
|
12
12
|
require 'vfs/ext/file'
|
13
|
+
require 'vfs/ext/file_test'
|
13
14
|
require 'vfs/ext/dir'
|
15
|
+
require 'vfs/ext/pathname'
|
14
16
|
require 'vfs/ext/kernel'
|
17
|
+
require 'vfs/ext/jdbc'
|
15
18
|
|
16
19
|
|
17
20
|
module ::VFS
|
18
21
|
def self.resolve_within_archive(path)
|
19
|
-
return path if ( path =~ %r(^vfs:) )
|
20
22
|
path = path.to_s
|
23
|
+
return path if ( path =~ %r(^vfs:) )
|
21
24
|
cur = path
|
22
25
|
while ( cur != '.' && cur != '/' )
|
23
26
|
if ( ::File.exist_without_vfs?( cur ) )
|
24
|
-
|
27
|
+
|
25
28
|
child_path = path[cur.length..-1]
|
26
29
|
|
27
30
|
if ( cur[-1,1] == '/' )
|
@@ -35,7 +38,7 @@ module ::VFS
|
|
35
38
|
end
|
36
39
|
|
37
40
|
def self.resolve_path_url(path)
|
38
|
-
prefix = case
|
41
|
+
prefix = case
|
39
42
|
when path =~ /^\// # unix absolute
|
40
43
|
"vfs:"
|
41
44
|
when path =~ /^[[:alpha:]]:/ # windows absolute
|
@@ -46,4 +49,31 @@ module ::VFS
|
|
46
49
|
"#{prefix}#{path}"
|
47
50
|
end
|
48
51
|
|
52
|
+
def self.virtual_file(filename)
|
53
|
+
vfs_url, child_path = VFS.resolve_within_archive( filename )
|
54
|
+
return nil unless vfs_url
|
55
|
+
|
56
|
+
begin
|
57
|
+
virtual_file = Java::org.jboss.vfs.VFS.child( vfs_url )
|
58
|
+
virtual_file = virtual_file.get_child( child_path ) if child_path
|
59
|
+
virtual_file
|
60
|
+
rescue Java::JavaIo::IOException => e
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.writable_path_or_error(path, e)
|
66
|
+
virtual_file = VFS.virtual_file( path )
|
67
|
+
raise e if virtual_file.nil?
|
68
|
+
mount = Java::org.jboss.vfs::VFS.get_mount(virtual_file)
|
69
|
+
# TODO: Replace with a better error stating the issue, which is
|
70
|
+
# the user is trying to write to a filesystem inside an archive
|
71
|
+
# that is mounted as readonly
|
72
|
+
#
|
73
|
+
# HACK: For some reason mount.file_system doesn't work inside TB
|
74
|
+
# but does in tests
|
75
|
+
# raise e if mount.file_system.read_only?
|
76
|
+
virtual_file.physical_file.path
|
77
|
+
end
|
78
|
+
|
49
79
|
end
|
data/spec/dir_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
require 'fileutils'
|
2
3
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
4
|
|
4
5
|
describe "Dir extensions for VFS" do
|
@@ -33,16 +34,23 @@ describe "Dir extensions for VFS" do
|
|
33
34
|
items.should include File.join( "vfs:#{@archive1_path}", 'web.xml' )
|
34
35
|
items.should include File.join( "vfs:#{@archive1_path}", 'lib' )
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
it "should allow globbing within nested archives with explicit vfs" do
|
38
39
|
pattern = "vfs:#{@archive2_path}/*"
|
39
40
|
items = Dir.glob( pattern )
|
40
41
|
items.should_not be_empty
|
41
42
|
items.should include "vfs:#{@archive2_path}/manifest.txt"
|
42
43
|
end
|
44
|
+
|
45
|
+
it "should create new Dirs" do
|
46
|
+
lambda {
|
47
|
+
Dir.new("vfs:#{@archive2_path}")
|
48
|
+
}.should_not raise_error
|
49
|
+
end
|
43
50
|
end
|
44
|
-
|
45
|
-
[ :absolute, :relative ].each do |style|
|
51
|
+
|
52
|
+
[ :absolute, :relative, :vfs ].each do |style|
|
53
|
+
#[ :relative ].each do |style|
|
46
54
|
describe "with #{style} paths" do
|
47
55
|
|
48
56
|
case ( style )
|
@@ -50,6 +58,25 @@ describe "Dir extensions for VFS" do
|
|
50
58
|
prefix = "./#{TEST_DATA_BASE}"
|
51
59
|
when :absolute
|
52
60
|
prefix = File.expand_path( File.join( File.dirname( __FILE__ ), '..', TEST_DATA_BASE ) )
|
61
|
+
when :vfs
|
62
|
+
prefix = "vfs:" + File.expand_path( File.join( File.dirname( __FILE__ ), '..', TEST_DATA_BASE ) )
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should ignore dotfiles by default" do
|
66
|
+
items = Dir.glob( "#{prefix}/dotfiles/*" )
|
67
|
+
items.should_not be_empty
|
68
|
+
items.size.should eql(3)
|
69
|
+
items.should include( "#{prefix}/dotfiles/one" )
|
70
|
+
items.should include( "#{prefix}/dotfiles/three" )
|
71
|
+
items.should include( "#{prefix}/dotfiles/foo.txt" )
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should match dotfiles if explicitly asked" do
|
75
|
+
items = Dir.glob( "#{prefix}/dotfiles/.*" )
|
76
|
+
items.should_not be_empty
|
77
|
+
items.size.should eql(2)
|
78
|
+
items.should include( "#{prefix}/dotfiles/.two" )
|
79
|
+
items.should include( "#{prefix}/dotfiles/.four" )
|
53
80
|
end
|
54
81
|
|
55
82
|
it "should allow globbing without any special globbing characters on normal files" do
|
@@ -57,7 +84,7 @@ describe "Dir extensions for VFS" do
|
|
57
84
|
items.should_not be_empty
|
58
85
|
items.should include( "#{prefix}/home/larry" )
|
59
86
|
end
|
60
|
-
|
87
|
+
|
61
88
|
it "should allow globbing without any special globbing characters on a single normal file" do
|
62
89
|
items = Dir.glob( "#{prefix}/home/larry/file1.txt" )
|
63
90
|
items.should_not be_empty
|
@@ -91,7 +118,7 @@ describe "Dir extensions for VFS" do
|
|
91
118
|
it "should allow appropriate globbing of normal files" do
|
92
119
|
items = Dir.glob( "#{prefix}/home/larry/*" )
|
93
120
|
items.should_not be_empty
|
94
|
-
items.should include( "#{prefix}/home/larry/file1.txt" )
|
121
|
+
items.should include( "#{prefix}/home/larry/file1.txt" )
|
95
122
|
items.should include( "#{prefix}/home/larry/file2.txt" )
|
96
123
|
items.should include( "#{prefix}/home/larry/archive1.jar" )
|
97
124
|
end
|
@@ -100,14 +127,14 @@ describe "Dir extensions for VFS" do
|
|
100
127
|
items = Dir.glob( "#{@archive1_path}/*" )
|
101
128
|
items.should_not be_empty
|
102
129
|
end
|
103
|
-
|
130
|
+
|
104
131
|
it "should determine if VFS is needed for nested archives" do
|
105
132
|
base = "#{prefix}/home/larry/archive1.jar/lib/archive2.jar"
|
106
133
|
items = Dir.glob( "#{base}/*" )
|
107
134
|
items.should_not be_empty
|
108
135
|
items.should include( "#{base}/manifest.txt" )
|
109
136
|
end
|
110
|
-
|
137
|
+
|
111
138
|
it "should determine if VFS is needed with relative paths" do
|
112
139
|
base = "#{prefix}/home/larry/archive1.jar/lib/archive2.jar"
|
113
140
|
items = Dir.glob( "#{base}/*" )
|
@@ -153,6 +180,31 @@ describe "Dir extensions for VFS" do
|
|
153
180
|
items.should_not include( "#{prefix}/home/larry/archive1.jar/lib/archive4.txt" )
|
154
181
|
end
|
155
182
|
|
183
|
+
it "should create new Dirs" do
|
184
|
+
lambda {
|
185
|
+
Dir.new(prefix)
|
186
|
+
}.should_not raise_error
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "mkdir" do
|
193
|
+
it "should mkdir inside vfs archive when directory mounted on filesystem" do
|
194
|
+
FileUtils.rm_rf "target/mnt"
|
195
|
+
archive = org.jboss.vfs::VFS.child( @archive1_path )
|
196
|
+
logical = archive.getChild( "lib" )
|
197
|
+
physical = java.io::File.new( "target/mnt" )
|
198
|
+
physical.mkdirs
|
199
|
+
mount = org.jboss.vfs::VFS.mountReal( physical, logical )
|
200
|
+
begin
|
201
|
+
lambda {
|
202
|
+
Dir.mkdir("#{@archive1_path}/lib/should_mkdir_inside_vfs_archive")
|
203
|
+
File.directory?("target/mnt/should_mkdir_inside_vfs_archive").should be_true
|
204
|
+
}.should_not raise_error
|
205
|
+
ensure
|
206
|
+
mount.close
|
207
|
+
end
|
156
208
|
end
|
157
209
|
end
|
158
210
|
|
data/spec/file_spec.rb
CHANGED
@@ -40,19 +40,33 @@ describe "File extensions for VFS" do
|
|
40
40
|
File.writable?( url ).should be_true
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
describe "expand_path" do
|
44
|
+
it "should handle relative non-vfs path" do
|
45
|
+
File.expand_path("../foo", "/tmp/bar").should == "/tmp/foo"
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
it "should handle relative to vfs path" do
|
49
|
+
File.expand_path("../foo", "vfs:/tmp/bar").should == "vfs:/tmp/foo"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should expand paths relative to VFS urls as VFS" do
|
53
|
+
absolute = File.expand_path("db/development.sqlite3", "vfs:/path/to/app")
|
54
|
+
absolute.should eql("vfs:/path/to/app/db/development.sqlite3")
|
55
|
+
end
|
52
56
|
|
53
|
-
|
54
|
-
|
55
|
-
|
57
|
+
it "should expand paths relative to VFS pathnames as VFS" do
|
58
|
+
absolute = File.expand_path("db/development.sqlite3", Pathname.new("vfs:/path/to/app"))
|
59
|
+
absolute.should eql("vfs:/path/to/app/db/development.sqlite3")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should expand absolute Pathname objects correctly" do
|
63
|
+
File.expand_path("vfs:/foo").should eql("vfs:/foo")
|
64
|
+
File.expand_path(Pathname.new("vfs:/foo")).should eql("vfs:/foo")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return first path when given two vfs paths" do
|
68
|
+
File.expand_path("vfs:/tmp/foo", "vfs:/tmp/bar").should == "vfs:/tmp/foo"
|
69
|
+
end
|
56
70
|
end
|
57
71
|
|
58
72
|
it "should handle vfs urls as readable" do
|
@@ -60,6 +74,16 @@ describe "File extensions for VFS" do
|
|
60
74
|
File.readable?( "vfs:#{__FILE__}" ).should be_true
|
61
75
|
end
|
62
76
|
|
77
|
+
it "should report readable-ness for files inside vfs archives" do
|
78
|
+
path = "vfs:#{@archive1_path}/web.xml"
|
79
|
+
File.readable?( path ).should be_true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should report readable-ness for non-existent files inside vfs archives" do
|
83
|
+
path = "vfs:#{@archive1_path}/file_that_does_not_exist.txt"
|
84
|
+
File.readable?( path ).should be_false
|
85
|
+
end
|
86
|
+
|
63
87
|
it "should handle #'s in filenames properly" do
|
64
88
|
prefix = File.expand_path( File.join( File.dirname( __FILE__ ), '..', TEST_COPY_BASE ) )
|
65
89
|
File.file?( "#{prefix}/#bad-uri#" ).should be_true
|
@@ -67,13 +91,26 @@ describe "File extensions for VFS" do
|
|
67
91
|
File.file?( "vfs:#{prefix}/#missing#" ).should be_false
|
68
92
|
end
|
69
93
|
|
94
|
+
it "should handle spaces in filenames properly" do
|
95
|
+
prefix = File.expand_path( File.join( File.dirname( __FILE__ ), '..', TEST_COPY_BASE ) )
|
96
|
+
File.file?( "#{prefix}/sound of music/flibbity jibbit" ).should be_true
|
97
|
+
File.file?( "vfs:#{prefix}/sound of music/flibbity jibbit" ).should be_true
|
98
|
+
File.file?( "vfs:#{prefix}/sound of music/flibberty gibbet" ).should be_false
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should handle backslashes in filenames even though there's no good reason to use them regardless of platform" do
|
102
|
+
filename = __FILE__.gsub("/","\\")
|
103
|
+
File.readable?( filename ).should be_true
|
104
|
+
File.readable?( "vfs:#{filename}" ).should be_true
|
105
|
+
end
|
106
|
+
|
70
107
|
it "should be able to chmod real files with vfs urls" do
|
71
108
|
path = File.expand_path("foo")
|
72
109
|
begin
|
73
110
|
f = File.new(path, "w")
|
74
|
-
FileUtils.chmod(
|
111
|
+
FileUtils.chmod( 0666, "vfs:#{path}")
|
75
112
|
m1 = f.stat.mode
|
76
|
-
FileUtils.chmod(
|
113
|
+
FileUtils.chmod( 0644, "vfs:#{path}")
|
77
114
|
m2 = f.stat.mode
|
78
115
|
m1.should_not eql(m2)
|
79
116
|
ensure
|
@@ -81,6 +118,28 @@ describe "File extensions for VFS" do
|
|
81
118
|
end
|
82
119
|
end
|
83
120
|
|
121
|
+
it "should chmod inside vfs archive when directory mounted on filesystem" do
|
122
|
+
FileUtils.rm_rf "target/mnt"
|
123
|
+
archive = org.jboss.vfs::VFS.child( @archive1_path )
|
124
|
+
logical = archive.getChild( "lib" )
|
125
|
+
physical = java.io::File.new( "target/mnt" )
|
126
|
+
physical.mkdirs
|
127
|
+
mount = org.jboss.vfs::VFS.mountReal( physical, logical )
|
128
|
+
path = "#{@archive1_path}/lib/chmod_test"
|
129
|
+
begin
|
130
|
+
lambda {
|
131
|
+
f = File.new ("target/mnt/chmod_test", "w" )
|
132
|
+
FileUtils.chmod( 0666, path )
|
133
|
+
m1 = f.stat.mode
|
134
|
+
FileUtils.chmod( 0755, path )
|
135
|
+
m2 = f.stat.mode
|
136
|
+
m1.should_not eql(m2)
|
137
|
+
}.should_not raise_error
|
138
|
+
ensure
|
139
|
+
mount.close
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
84
143
|
it "should be able to create new files with vfs urls" do
|
85
144
|
lambda {
|
86
145
|
File.new("vfs:#{__FILE__}", 'r')
|
@@ -95,13 +154,18 @@ describe "File extensions for VFS" do
|
|
95
154
|
|
96
155
|
describe "open" do
|
97
156
|
it "should return File when called on File with VFS url" do
|
98
|
-
puts @archive1_path
|
99
157
|
File.open("vfs:#{@archive1_path}", 'r').should be_an_instance_of(File)
|
100
158
|
end
|
101
159
|
|
102
160
|
it "should return File when called on File without VFS url" do
|
103
161
|
File.open(@archive1_path, 'r').should be_an_instance_of(File)
|
104
162
|
end
|
163
|
+
|
164
|
+
it "should find files by pathnames" do
|
165
|
+
lambda {
|
166
|
+
File.open(Pathname.new(@archive1_path), 'r')
|
167
|
+
}.should_not raise_error
|
168
|
+
end
|
105
169
|
end
|
106
170
|
|
107
171
|
describe "new" do
|
@@ -112,6 +176,11 @@ describe "File extensions for VFS" do
|
|
112
176
|
it "should return File when called on File without VFS url" do
|
113
177
|
File.new(@archive1_path, 'r').should be_an_instance_of(File)
|
114
178
|
end
|
179
|
+
|
180
|
+
xit "should create objects that respond to lstat for files in an archive" do
|
181
|
+
file = File.new( "vfs:#{@archive1_path}/web.xml")
|
182
|
+
file.lstat.should_not be_nil
|
183
|
+
end
|
115
184
|
end
|
116
185
|
|
117
186
|
[ :absolute, :relative, :vfs ].each do |style|
|
@@ -125,6 +194,31 @@ describe "File extensions for VFS" do
|
|
125
194
|
prefix = "vfs:#{File.expand_path( File.join( File.dirname( __FILE__ ), '..', TEST_COPY_BASE ) )}"
|
126
195
|
end
|
127
196
|
|
197
|
+
it "should provide size for normal files" do
|
198
|
+
s = File.size( "#{prefix}/home/larry/file1.txt" )
|
199
|
+
s.should_not be_nil
|
200
|
+
s.should be > 0
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should throw NOENT for size of non-existant files" do
|
204
|
+
lambda {
|
205
|
+
File.size( "#{prefix}/home/larry/NOT_REALLY_file1.txt" )
|
206
|
+
}.should raise_error
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should provide size? for normal files" do
|
210
|
+
s = File.size?( "#{prefix}/home/larry/file1.txt" )
|
211
|
+
s.should_not be_nil
|
212
|
+
s.should be > 0
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should not throw NOENT for size? of non-existant files" do
|
216
|
+
lambda {
|
217
|
+
s = File.size?( "#{prefix}/home/larry/NOT_REALLY_file1.txt" )
|
218
|
+
s.should be_nil
|
219
|
+
}.should_not raise_error
|
220
|
+
end
|
221
|
+
|
128
222
|
it "should provide mtime for normal files" do
|
129
223
|
mtime = File.mtime( "#{prefix}/home/larry/file1.txt" )
|
130
224
|
mtime.should_not be_nil
|
@@ -152,11 +246,18 @@ describe "File extensions for VFS" do
|
|
152
246
|
contents.should eql( "This is file 1\nhowdy\n" )
|
153
247
|
|
154
248
|
fs_file = File.join( File.dirname(__FILE__), '..', TEST_COPY_BASE, 'home/larry/file1.txt' )
|
155
|
-
puts "confirm from #{fs_file}"
|
156
249
|
fs_contents = File.read( fs_file )
|
157
250
|
fs_contents.should eql( "This is file 1\nhowdy\n" )
|
158
251
|
end
|
159
252
|
|
253
|
+
it "should allow writing new files via File.open" do
|
254
|
+
File.open( "#{prefix}/home/larry/new_file.txt", 'w' ) do |file|
|
255
|
+
file.puts "howdy"
|
256
|
+
end
|
257
|
+
contents = File.read( "#{prefix}/home/larry/new_file.txt" )
|
258
|
+
contents.should eql( "howdy\n")
|
259
|
+
end
|
260
|
+
|
160
261
|
it "should allow stat for normal files" do
|
161
262
|
file = "#{prefix}/home/larry/file1.txt"
|
162
263
|
stat = File.stat( file )
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "File extensions for VFS" do
|
4
|
+
|
5
|
+
it "should delegate to File.directory?" do
|
6
|
+
delegate_to_file(:directory?, 'file')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should delegate to File.exist?" do
|
10
|
+
delegate_to_file(:exist?, 'file')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should delegate to File.exists?" do
|
14
|
+
delegate_to_file(:exists?, 'file')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should delegate to File.file?" do
|
18
|
+
delegate_to_file(:file?, 'file')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should delegate to File.readable?" do
|
22
|
+
delegate_to_file(:readable?, 'file')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should delegate to File.writable?" do
|
26
|
+
delegate_to_file(:writable?, 'file')
|
27
|
+
end
|
28
|
+
|
29
|
+
def delegate_to_file(*args)
|
30
|
+
method = args.shift
|
31
|
+
File.should_receive(method).with(*args).and_return('value')
|
32
|
+
FileTest.send(method, *args).should == 'value'
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
describe "Pathname extensions for VFS" do
|
6
|
+
|
7
|
+
describe "realpath" do
|
8
|
+
it "should expand VFS paths" do
|
9
|
+
pathname = Pathname.new("vfs:/tmp/test")
|
10
|
+
pathname.should_receive(:expand_path).and_return(Pathname.new("/expanded/path"))
|
11
|
+
pathname.realpath.to_s.should == "/expanded/path"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should find real path for non-VFS paths" do
|
15
|
+
pathname = Pathname.new("/tmp/test")
|
16
|
+
pathname.should_receive(:realpath_without_vfs).and_return(Pathname.new("/real/path"))
|
17
|
+
pathname.realpath.to_s.should == "/real/path"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
+
|
4
|
+
describe "VFS::Dir" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@executor = java.util.concurrent::Executors.newScheduledThreadPool( 1 )
|
8
|
+
@temp_file_provider = org.jboss.vfs::TempFileProvider.create( "vfs-test", @executor )
|
9
|
+
@archive1_path = File.expand_path( "#{TEST_DATA_DIR}/home/larry/archive1.jar" )
|
10
|
+
@archive1_file = org.jboss.vfs::VFS.child( @archive1_path )
|
11
|
+
@archive1_mount_point = org.jboss.vfs::VFS.child( @archive1_path )
|
12
|
+
@archive1_handle = org.jboss.vfs::VFS.mountZip( @archive1_file, @archive1_mount_point, @temp_file_provider )
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
@archive1_handle.close
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "entries" do
|
20
|
+
it "should find vfs entries outside of archives" do
|
21
|
+
path = "#{@archive1_path}/.."
|
22
|
+
::Dir.new( path ).entries.should == VFS::Dir.new( "vfs:#{path}" ).entries
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should find vfs entries inside of archives" do
|
26
|
+
path = "vfs:#{@archive1_path}/other_lib/subdir"
|
27
|
+
entries = VFS::Dir.new( path ).entries
|
28
|
+
entries.size.should == 1
|
29
|
+
entries.first.should == "archive6.jar"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/vfs_spec.rb
CHANGED
@@ -1,20 +1,31 @@
|
|
1
|
+
require 'pathname'
|
1
2
|
|
2
3
|
describe "VFS path resolution" do
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe "resolve_within_archive" do
|
6
|
+
it "should return pathnames with vfs: prefix unmodified" do
|
7
|
+
pathname = Pathname.new("vfs:/tmp/foo")
|
8
|
+
path = VFS.resolve_within_archive(pathname)
|
9
|
+
path.should == pathname.to_s
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
describe "resolve_path_url" do
|
14
|
+
it "should prefix relative paths with the current dir" do
|
15
|
+
cwd = Dir.pwd
|
16
|
+
path = VFS.resolve_path_url( "foo/bar" )
|
17
|
+
path.should match /^vfs:#{cwd}\/foo\/bar$/
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not prefix absolute paths with the current dir" do
|
21
|
+
path = VFS.resolve_path_url( "/foo/bar" )
|
22
|
+
path.should match /^vfs:\/foo\/bar$/
|
23
|
+
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
25
|
+
it "should treat paths with windows drive letters as absolute" do
|
26
|
+
path = VFS.resolve_path_url( "C:/foo/bar" )
|
27
|
+
path.should match /^vfs:\/C:\/foo\/bar$/
|
28
|
+
end
|
18
29
|
end
|
19
30
|
|
20
31
|
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 1
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.0.
|
9
|
+
- Beta23
|
10
|
+
version: 1.0.0.Beta23
|
11
11
|
platform: ruby
|
12
12
|
authors: []
|
13
13
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-06 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -62,13 +62,19 @@ files:
|
|
62
62
|
- lib/vfs/glob_filter.rb
|
63
63
|
- lib/vfs/ext/dir.rb
|
64
64
|
- lib/vfs/ext/file.rb
|
65
|
+
- lib/vfs/ext/file_test.rb
|
65
66
|
- lib/vfs/ext/io.rb
|
67
|
+
- lib/vfs/ext/jdbc.rb
|
66
68
|
- lib/vfs/ext/kernel.rb
|
69
|
+
- lib/vfs/ext/pathname.rb
|
67
70
|
- lib/vfs/ext/vfs.rb
|
68
71
|
- spec/dir_spec.rb
|
69
72
|
- spec/file_spec.rb
|
73
|
+
- spec/file_test_spec.rb
|
70
74
|
- spec/io_spec.rb
|
75
|
+
- spec/pathname_spec.rb
|
71
76
|
- spec/spec_helper.rb
|
77
|
+
- spec/vfs_dir_spec.rb
|
72
78
|
- spec/vfs_spec.rb
|
73
79
|
has_rdoc: true
|
74
80
|
homepage: http://www.torquebox.org/vfs/
|
@@ -105,5 +111,8 @@ summary: TorqueBox VFS
|
|
105
111
|
test_files:
|
106
112
|
- spec/dir_spec.rb
|
107
113
|
- spec/file_spec.rb
|
114
|
+
- spec/file_test_spec.rb
|
108
115
|
- spec/io_spec.rb
|
116
|
+
- spec/pathname_spec.rb
|
117
|
+
- spec/vfs_dir_spec.rb
|
109
118
|
- spec/vfs_spec.rb
|