el_finder 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/el_finder/connector.rb +19 -18
- data/lib/el_finder/pathname.rb +144 -40
- data/lib/el_finder/version.rb +1 -1
- data/test/el_finder/test_mime_type.rb +1 -1
- data/test/el_finder/test_pathname.rb +228 -59
- data/test/test_el_finder.rb +12 -0
- data/test/test_el_finder_hash.rb +3 -3
- data/test/test_el_finder_symlink.rb +0 -2
- metadata +4 -4
data/lib/el_finder/connector.rb
CHANGED
@@ -63,12 +63,12 @@ module ElFinder
|
|
63
63
|
|
64
64
|
#
|
65
65
|
def to_hash(pathname)
|
66
|
-
Base64.encode64(pathname
|
66
|
+
Base64.encode64(pathname.path.to_s).chomp
|
67
67
|
end # of to_hash
|
68
68
|
|
69
69
|
#
|
70
70
|
def from_hash(hash)
|
71
|
-
pathname =
|
71
|
+
pathname = @root + Base64.decode64(hash)
|
72
72
|
end # of from_hash
|
73
73
|
|
74
74
|
#
|
@@ -154,7 +154,7 @@ module ElFinder
|
|
154
154
|
end
|
155
155
|
|
156
156
|
file = @current + @params[:name]
|
157
|
-
if !file.exist? &&
|
157
|
+
if !file.exist? && file.touch
|
158
158
|
@response[:select] = [to_hash(file)]
|
159
159
|
_open(@current)
|
160
160
|
else
|
@@ -199,7 +199,7 @@ module ElFinder
|
|
199
199
|
select = []
|
200
200
|
@params[:upload].to_a.each do |file|
|
201
201
|
dst = @current + @options[:original_filename_method].call(file)
|
202
|
-
FileUtils.mv(file.path, dst)
|
202
|
+
FileUtils.mv(file.path, dst.fullpath)
|
203
203
|
select << to_hash(dst)
|
204
204
|
end
|
205
205
|
@response[:select] = select
|
@@ -227,15 +227,15 @@ module ElFinder
|
|
227
227
|
dst = from_hash(@params[:dst]) + src.basename
|
228
228
|
if dst.exist?
|
229
229
|
@response[:error] ||= 'Some files were unable to be copied'
|
230
|
-
@response[:errorData][src.basename.to_s] = "already exists in '#{dst.dirname
|
230
|
+
@response[:errorData][src.basename.to_s] = "already exists in '#{dst.dirname}'"
|
231
231
|
else
|
232
232
|
if @params[:cut].to_i > 0
|
233
233
|
src.rename(dst)
|
234
234
|
else
|
235
235
|
if src.directory?
|
236
|
-
FileUtils.cp_r(src, dst)
|
236
|
+
FileUtils.cp_r(src.fullpath, dst.fullpath)
|
237
237
|
else
|
238
|
-
FileUtils.
|
238
|
+
FileUtils.cp(src.fullpath, dst.fullpath)
|
239
239
|
end
|
240
240
|
end
|
241
241
|
end
|
@@ -273,9 +273,9 @@ module ElFinder
|
|
273
273
|
|
274
274
|
duplicate = @target.duplicate
|
275
275
|
if @target.directory?
|
276
|
-
FileUtils.cp_r(@target, duplicate)
|
276
|
+
FileUtils.cp_r(@target, duplicate.fullpath)
|
277
277
|
else
|
278
|
-
FileUtils.copy(@target, duplicate)
|
278
|
+
FileUtils.copy(@target, duplicate.fullpath)
|
279
279
|
end
|
280
280
|
@response[:select] = [to_hash(duplicate)]
|
281
281
|
_open(@current)
|
@@ -321,8 +321,8 @@ module ElFinder
|
|
321
321
|
@response[:error] = 'Access Denied' and return unless !@targets.nil? && @targets.all?{|e| perms_for(e)[:read]} && perms_for(@current)[:write] == true
|
322
322
|
@response[:error] = 'No archiver available for this file type' and return if (archiver = @options[:archivers][@params[:type]]).nil?
|
323
323
|
extension = archiver.shift
|
324
|
-
basename = @params[:name] || @targets.first.
|
325
|
-
archive =
|
324
|
+
basename = @params[:name] || @targets.first.basename_sans_extension
|
325
|
+
archive = (@root + "#{basename}#{extension}").unique
|
326
326
|
cmd = ['cd', @current.to_s.shellescape, '&&', archiver.map(&:shellescape), archive.to_s.shellescape, @targets.map{|t| t.basename.to_s.shellescape}].flatten.join(' ')
|
327
327
|
if system(cmd)
|
328
328
|
@response[:select] = [to_hash(archive)]
|
@@ -401,7 +401,7 @@ module ElFinder
|
|
401
401
|
:name => pathname.basename.to_s,
|
402
402
|
:hash => to_hash(pathname),
|
403
403
|
:mime => 'directory',
|
404
|
-
:rel => (@options[:home] + '/' + pathname.
|
404
|
+
:rel => pathname.is_root? ? @options[:home] : (@options[:home] + '/' + pathname.path.to_s),
|
405
405
|
:size => 0,
|
406
406
|
:date => pathname.mtime.to_s,
|
407
407
|
}.merge(perms_for(pathname))
|
@@ -424,7 +424,7 @@ module ElFinder
|
|
424
424
|
response.merge!(
|
425
425
|
:size => pathname.size,
|
426
426
|
:mime => mime_handler.for(pathname),
|
427
|
-
:url => (@options[:url] + '/' + pathname.
|
427
|
+
:url => (@options[:url] + '/' + pathname.path.to_s)
|
428
428
|
)
|
429
429
|
|
430
430
|
if pathname.readable? && response[:mime] =~ /image/ && !image_size_handler.nil? && !image_resize_handler.nil?
|
@@ -438,9 +438,9 @@ module ElFinder
|
|
438
438
|
|
439
439
|
if pathname.symlink?
|
440
440
|
response.merge!(
|
441
|
-
:link => to_hash(
|
442
|
-
:linkTo =>
|
443
|
-
:parent => to_hash(
|
441
|
+
:link => to_hash(@root + pathname.readlink), # hash of file to which point link
|
442
|
+
:linkTo => (@root + pathname.readlink).relative_to(pathname.dirname.path).to_s, # relative path to
|
443
|
+
:parent => to_hash((@root + pathname.readlink).dirname) # hash of directory in which is linked file
|
444
444
|
)
|
445
445
|
end
|
446
446
|
|
@@ -470,7 +470,7 @@ module ElFinder
|
|
470
470
|
response[:write] &&= specific_perm_for(pathname, :write)
|
471
471
|
response[:write] &&= @options[:default_perms][:write]
|
472
472
|
|
473
|
-
response[:rm] = pathname
|
473
|
+
response[:rm] = !pathname.is_root?
|
474
474
|
response[:rm] &&= specific_perm_for(pathname, :rm)
|
475
475
|
response[:rm] &&= @options[:default_perms][:rm]
|
476
476
|
|
@@ -479,7 +479,8 @@ module ElFinder
|
|
479
479
|
|
480
480
|
#
|
481
481
|
def specific_perm_for(pathname, perm)
|
482
|
-
|
482
|
+
pathname = pathname.path if pathname.is_a?(ElFinder::Pathname)
|
483
|
+
@options[:perms].select{ |k,v| pathname.to_s.send((k.is_a?(String) ? :== : :match), k) }.none?{|e| e.last[perm] == false}
|
483
484
|
end # of specific_perm_for
|
484
485
|
|
485
486
|
#
|
data/lib/el_finder/pathname.rb
CHANGED
@@ -3,75 +3,179 @@ require 'pathname'
|
|
3
3
|
|
4
4
|
module ElFinder
|
5
5
|
|
6
|
-
class Pathname
|
6
|
+
class Pathname
|
7
|
+
attr_reader :root, :path
|
7
8
|
|
9
|
+
#
|
10
|
+
def initialize(root, path = '.')
|
11
|
+
@root = root.is_a?(ElFinder::Pathname) ? root.root : ::Pathname.new(root)
|
12
|
+
|
13
|
+
@path = ::Pathname.new(path)
|
14
|
+
@path = path.is_a?(ElFinder::Pathname) ? path.path : ::Pathname.new(path)
|
15
|
+
if absolute?
|
16
|
+
if @path.cleanpath.to_s.start_with?(@root.to_s)
|
17
|
+
@path = ::Pathname.new @path.to_s.slice((@root.to_s.length + 1)..-1)
|
18
|
+
elsif @path.cleanpath.to_s.start_with?(@root.realpath.to_s)
|
19
|
+
@path = ::Pathname.new @path.to_s.slice((@root.realpath.to_s.length + 1)..-1)
|
20
|
+
else
|
21
|
+
raise SecurityError, "Absolute paths are not allowed"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
raise SecurityError, "Paths outside the root are not allowed" if outside_of_root?
|
25
|
+
|
26
|
+
end # of initialize
|
27
|
+
|
8
28
|
#
|
9
29
|
def +(other)
|
10
|
-
|
11
|
-
|
30
|
+
if other.is_a? ::ElFinder::Pathname
|
31
|
+
other = other.path
|
32
|
+
end
|
33
|
+
self.class.new(@root, (@path + other).to_s)
|
34
|
+
end # of +
|
12
35
|
|
13
36
|
#
|
14
|
-
def
|
15
|
-
|
37
|
+
def is_root?
|
38
|
+
@path.to_s == '.'
|
16
39
|
end
|
17
40
|
|
18
41
|
#
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
42
|
+
def absolute?
|
43
|
+
@path.absolute?
|
44
|
+
end # of absolute?
|
45
|
+
|
46
|
+
#
|
47
|
+
def relative?
|
48
|
+
@path.relative?
|
49
|
+
end # of relative?
|
50
|
+
|
51
|
+
#
|
52
|
+
def outside_of_root?
|
53
|
+
!cleanpath.to_s.start_with?(@root.to_s)
|
54
|
+
end # of outside_of_root?
|
55
|
+
|
56
|
+
#
|
57
|
+
def fullpath
|
58
|
+
@path.nil? ? @root : @root + @path
|
59
|
+
end # of fullpath
|
60
|
+
|
61
|
+
#
|
62
|
+
def cleanpath
|
63
|
+
fullpath.cleanpath
|
64
|
+
end # of cleanpath
|
65
|
+
|
66
|
+
#
|
67
|
+
def realpath
|
68
|
+
fullpath.realpath
|
69
|
+
end # of realpath
|
70
|
+
|
71
|
+
#
|
72
|
+
def basename(*args)
|
73
|
+
@path.basename(*args)
|
74
|
+
end # of basename
|
75
|
+
|
76
|
+
#
|
77
|
+
def basename_sans_extension
|
78
|
+
@path.basename(@path.extname)
|
79
|
+
end # of basename
|
80
|
+
|
81
|
+
#
|
82
|
+
def basename(*args)
|
83
|
+
@path.basename(*args)
|
84
|
+
end # of basename
|
85
|
+
|
86
|
+
#
|
87
|
+
def dirname
|
88
|
+
self.class.new(@root, @path.dirname)
|
89
|
+
end # of basename
|
90
|
+
|
91
|
+
#
|
92
|
+
def extname
|
93
|
+
@path.nil? ? '' : @path.extname
|
94
|
+
end # of extname
|
25
95
|
|
26
96
|
#
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
97
|
+
def to_s
|
98
|
+
cleanpath.to_s
|
99
|
+
end # of to_s
|
100
|
+
alias_method :to_str, :to_s
|
101
|
+
|
102
|
+
|
103
|
+
#
|
104
|
+
def children(with_directory=true)
|
105
|
+
realpath.children(with_directory).map{|e| self.class.new(@root, e)}
|
106
|
+
end
|
31
107
|
|
32
108
|
#
|
33
|
-
def
|
34
|
-
|
109
|
+
def touch(options = {})
|
110
|
+
FileUtils.touch(cleanpath, options)
|
35
111
|
end
|
36
112
|
|
113
|
+
#
|
114
|
+
def relative_to(other)
|
115
|
+
@path.relative_path_from(other)
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
def unique
|
120
|
+
return self.dup unless self.file?
|
121
|
+
copy = 1
|
122
|
+
begin
|
123
|
+
new_file = self.class.new(@root, dirname + "#{basename_sans_extension} #{copy}#{extname}")
|
124
|
+
copy += 1
|
125
|
+
end while new_file.exist?
|
126
|
+
new_file
|
127
|
+
end # of unique
|
128
|
+
|
37
129
|
#
|
38
130
|
def duplicate
|
39
|
-
|
40
|
-
|
41
|
-
_basename = basename(_extname)
|
42
|
-
copy = 0
|
131
|
+
_basename = basename_sans_extension
|
132
|
+
copy = 1
|
43
133
|
if _basename.to_s =~ /^(.*) copy (\d+)$/
|
44
134
|
_basename = $1
|
45
135
|
copy = $2.to_i
|
46
136
|
end
|
47
|
-
|
48
137
|
begin
|
138
|
+
new_file = self.class.new(@root, dirname + "#{_basename} copy #{copy}#{extname}")
|
49
139
|
copy += 1
|
50
|
-
new_file = self.class.superclass.new(_dirname + "#{_basename} copy #{copy}#{_extname}")
|
51
140
|
end while new_file.exist?
|
52
141
|
new_file
|
53
142
|
end # of duplicate
|
54
143
|
|
55
144
|
#
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
145
|
+
def rename(to)
|
146
|
+
to = self.class.new(@root, to.to_s)
|
147
|
+
realpath.rename(to.fullpath.to_s)
|
148
|
+
rescue Errno::EXDEV
|
149
|
+
FileUtils.move(realpath.to_s, to.fullpath.to_s)
|
150
|
+
ensure
|
151
|
+
@path = to.path
|
152
|
+
end # of rename
|
63
153
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
154
|
+
{
|
155
|
+
'directory?' => {:path => 'realpath', :rescue => true },
|
156
|
+
'exist?' => {:path => 'realpath', :rescue => true },
|
157
|
+
'file?' => {:path => 'realpath', :rescue => true },
|
158
|
+
'ftype' => {:path => 'realpath', },
|
159
|
+
'mkdir' => {:path => 'fullpath', :args => '(*args)' },
|
160
|
+
'mkdir' => {:path => 'fullpath', :args => '(*args)' },
|
161
|
+
'mtime' => {:path => 'realpath', },
|
162
|
+
'open' => {:path => 'fullpath', :args => '(*args, &block)' },
|
163
|
+
'read' => {:path => 'fullpath', :args => '(*args)' },
|
164
|
+
'readlink' => {:path => 'fullpath', },
|
165
|
+
'readable?' => {:path => 'realpath', :rescue => true },
|
166
|
+
'size' => {:path => 'realpath', },
|
167
|
+
'symlink?' => {:path => 'fullpath', },
|
168
|
+
'unlink' => {:path => 'realpath', },
|
169
|
+
'writable?' => {:path => 'realpath', :rescue => true },
|
170
|
+
}.each_pair do |meth, opts|
|
171
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
172
|
+
def #{meth}#{opts[:args]}
|
173
|
+
#{opts[:path]}.#{meth}#{opts[:args]}
|
174
|
+
#{"rescue Errno::ENOENT\nfalse" if opts[:rescue]}
|
175
|
+
end
|
176
|
+
METHOD
|
177
|
+
end
|
70
178
|
|
71
|
-
#
|
72
|
-
def relative_to(pathname)
|
73
|
-
self == pathname ? '' : relative_path_from(pathname).to_s
|
74
|
-
end # of relative_to
|
75
179
|
|
76
180
|
end # of class Pathname
|
77
181
|
|
data/lib/el_finder/version.rb
CHANGED
@@ -24,7 +24,7 @@ class TestMimeType < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_passing_pathname
|
27
|
-
assert_equal 'text/plain', ElFinder::MimeType.for(ElFinder::Pathname.new('README.txt'))
|
27
|
+
assert_equal 'text/plain', ElFinder::MimeType.for(ElFinder::Pathname.new('/tmp', 'README.txt'))
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'test/unit'
|
2
|
+
require 'el_finder'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'pp'
|
4
5
|
|
5
6
|
class TestPathname < Test::Unit::TestCase
|
6
7
|
|
@@ -16,64 +17,268 @@ class TestPathname < Test::Unit::TestCase
|
|
16
17
|
|
17
18
|
################################################################################
|
18
19
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def test_new_fails_without_root
|
21
|
+
assert_raise ArgumentError do
|
22
|
+
ElFinder::Pathname.new()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_new_okay_with_root
|
27
|
+
assert_nothing_raised do
|
28
|
+
ElFinder::Pathname.new(@vroot)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_new_okay_with_root_and_path
|
33
|
+
assert_nothing_raised do
|
34
|
+
ElFinder::Pathname.new(@vroot, 'foo.txt')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_instance_variables_are_set_correctly
|
39
|
+
p = ElFinder::Pathname.new(@vroot, 'foo.txt')
|
40
|
+
assert_equal @vroot, p.root.to_s
|
41
|
+
assert_equal 'foo.txt', p.path.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_instance_variables_are_set_correctly_with_nil_path
|
45
|
+
p = ElFinder::Pathname.new(@vroot)
|
46
|
+
assert_equal @vroot, p.root.to_s
|
47
|
+
assert_equal '.', p.path.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_instance_variables_are_kind_of_pathname
|
51
|
+
p = ElFinder::Pathname.new(@vroot, 'foo.txt')
|
52
|
+
assert_kind_of ::Pathname, p.root
|
53
|
+
assert_kind_of ::Pathname, p.path
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_attempt_to_break_out_of_root_using_relative_path
|
57
|
+
assert_raise SecurityError do
|
58
|
+
p = ElFinder::Pathname.new(@vroot, '../foo.txt')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_attempt_to_break_out_of_root_using_absolute_path
|
63
|
+
assert_raise SecurityError do
|
64
|
+
p = ElFinder::Pathname.new(@vroot, '/foo.txt')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_new_with_full_path_matching_root
|
69
|
+
p = ElFinder::Pathname.new(@vroot, "#{@vroot}/foo.txt")
|
70
|
+
assert_equal 'foo.txt', p.path.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_new_with_full_path_matching_root_realpath
|
74
|
+
p = ElFinder::Pathname.new(@vroot, "#{Pathname.new(@vroot).realpath.to_s}/foo.txt")
|
75
|
+
assert_equal 'foo.txt', p.path.to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_plus_string
|
79
|
+
p = ElFinder::Pathname.new(@vroot, 'foo')
|
80
|
+
p1 = p + 'bar'
|
81
|
+
assert_equal 'foo/bar', p1.path.to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_plus_pathname
|
85
|
+
p = ElFinder::Pathname.new(@vroot, 'foo')
|
86
|
+
p1 = p + Pathname.new('bar')
|
87
|
+
assert_equal 'foo/bar', p1.path.to_s
|
23
88
|
end
|
24
89
|
|
90
|
+
def test_plus_elfinder_pathname
|
91
|
+
p = ElFinder::Pathname.new(@vroot, 'foo')
|
92
|
+
p1 = p + ElFinder::Pathname.new(@vroot, 'bar')
|
93
|
+
assert_equal 'foo/bar', p1.path.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_fullpath
|
97
|
+
assert_equal "#{@vroot}/one/two/three.txt", ElFinder::Pathname.new(@vroot, 'one/two/three.txt').fullpath.to_s
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_file?
|
101
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'README.txt').file?, "README.txt should be a file"
|
102
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'INVALID').file?, "INVALID should not be a file"
|
103
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'foo').file?, "foo should not be a file (it's a directory)"
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_directory?
|
107
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'foo').directory?, "foo should be a directory"
|
108
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'README.txt').directory?, "README.txt should not be a directory (it's a file)"
|
109
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'INVALID').directory?, "INVALID should not be a directory"
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_exist?
|
113
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'foo').exist?, "foo should exist"
|
114
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'README.txt').exist?, "README.txt should exist"
|
115
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'INVALID').exist?, "INVALID should not exist"
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_symlink?
|
119
|
+
File.symlink(File.join(@vroot, 'README.txt'), File.join(@vroot, 'symlink.txt'))
|
120
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'symlink.txt').symlink?, "symlink.txt should be a symlink"
|
121
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'README.txt').symlink?, "README.txt should not be a symlink"
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_readable?
|
125
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'foo').readable?, "foo should be readable"
|
126
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'README.txt').readable?, "README.txt should be readable"
|
127
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'INVALID').readable?, "INVALID should not be readable"
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_writable?
|
131
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'foo').writable?, "foo should be writable"
|
132
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'README.txt').writable?, "README.txt should be writable"
|
133
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'INVALID').writable?, "INVALID should not be writable"
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_mtime
|
137
|
+
assert_equal File.new(File.join(@vroot, 'foo')).mtime, ElFinder::Pathname.new(@vroot, 'foo').mtime
|
138
|
+
assert_equal File.new(File.join(@vroot, 'README.txt')).mtime, ElFinder::Pathname.new(@vroot, 'README.txt').mtime
|
139
|
+
assert_raise Errno::ENOENT do
|
140
|
+
ElFinder::Pathname.new(@vroot, 'INVALID').mtime
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_unlink
|
145
|
+
assert_equal true, ElFinder::Pathname.new(@vroot, 'README.txt').exist?
|
146
|
+
ElFinder::Pathname.new(@vroot, 'README.txt').unlink
|
147
|
+
assert_equal false, ElFinder::Pathname.new(@vroot, 'README.txt').exist?
|
148
|
+
assert_raise Errno::ENOENT do
|
149
|
+
ElFinder::Pathname.new(@vroot, 'INVALID').unlink
|
150
|
+
end
|
151
|
+
assert_raise Errno::ENOTEMPTY do
|
152
|
+
ElFinder::Pathname.new(@vroot, 'foo').unlink
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_basename
|
157
|
+
assert_equal 'README.txt', ElFinder::Pathname.new(@vroot, 'README.txt').basename.to_s
|
158
|
+
assert_equal 'README', ElFinder::Pathname.new(@vroot, 'README.txt').basename('.txt').to_s
|
159
|
+
assert_equal 'tom.txt', ElFinder::Pathname.new(@vroot, 'foo/tom.txt').basename.to_s
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_basename_sans_extension
|
163
|
+
assert_equal 'README', ElFinder::Pathname.new(@vroot, 'README.txt').basename_sans_extension.to_s
|
164
|
+
assert_equal 'tom', ElFinder::Pathname.new(@vroot, 'foo/tom.txt').basename_sans_extension.to_s
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_dirname
|
168
|
+
assert_equal '.', ElFinder::Pathname.new(@vroot, 'README.txt').dirname.path.to_s
|
169
|
+
assert_equal 'foo', ElFinder::Pathname.new(@vroot, 'foo/tom.txt').dirname.path.to_s
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_to_s
|
173
|
+
assert_equal "#{@vroot}/README.txt", ElFinder::Pathname.new(@vroot, 'README.txt').to_s
|
174
|
+
assert_equal "#{@vroot}/foo/tom.txt", ElFinder::Pathname.new(@vroot, 'foo/tom.txt').to_s
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_children
|
178
|
+
children = ElFinder::Pathname.new(@vroot, 'foo').children
|
179
|
+
assert_equal 4, children.size
|
180
|
+
assert_equal %w[philip sam sandy tom], children.map{|e| e.basename_sans_extension.to_s}.sort
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_mkdir
|
184
|
+
p = ElFinder::Pathname.new(@vroot, 'some-dir')
|
185
|
+
assert_equal false, p.directory?
|
186
|
+
p.mkdir
|
187
|
+
assert_equal true, p.directory?
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_read
|
191
|
+
p = ElFinder::Pathname.new(@vroot, 'foo/philip.txt')
|
192
|
+
assert_equal File.read(File.join(@vroot, 'foo/philip.txt')), p.read
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_touch
|
196
|
+
p = ElFinder::Pathname.new(@vroot, 'newfile')
|
197
|
+
p.touch
|
198
|
+
assert_equal true, p.file?
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_open
|
202
|
+
p = ElFinder::Pathname.new(@vroot, 'newfile')
|
203
|
+
assert_equal false, p.file?
|
204
|
+
p.open('w') {|f| f.puts "new"}
|
205
|
+
assert_equal true, p.file?
|
206
|
+
assert_equal File.read(File.join(@vroot, 'newfile')), p.read
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_unique_on_create
|
210
|
+
file = ElFinder::Pathname.new(@vroot, 'foo.txt')
|
211
|
+
assert_equal 'foo.txt', file.unique.basename.to_s
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_unique_conflict
|
215
|
+
file = ElFinder::Pathname.new(@vroot, 'pjkh.png')
|
216
|
+
assert_equal 'pjkh 1.png', file.unique.basename.to_s
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_unique_conflict_twice
|
220
|
+
ElFinder::Pathname.new(@vroot, 'pjkh 1.png').touch
|
221
|
+
file = ElFinder::Pathname.new(@vroot, 'pjkh.png')
|
222
|
+
assert_equal 'pjkh 2.png', file.unique.basename.to_s
|
223
|
+
end
|
224
|
+
|
225
|
+
|
25
226
|
def test_duplication_without_extension
|
26
|
-
assert_equal File.join(@vroot, 'README copy 1'), ElFinder::Pathname.
|
227
|
+
assert_equal File.join(@vroot, 'README copy 1'), ElFinder::Pathname.new(@vroot,'README').duplicate.fullpath.to_s
|
27
228
|
end
|
28
229
|
|
29
230
|
def test_2nd_duplication_without_extension
|
30
231
|
::FileUtils.touch(File.join(@vroot, 'README copy 1'))
|
31
|
-
assert_equal File.join(@vroot, 'README copy 2'), ElFinder::Pathname.
|
232
|
+
assert_equal File.join(@vroot, 'README copy 2'), ElFinder::Pathname.new(@vroot,'README').duplicate.fullpath.to_s
|
32
233
|
end
|
33
234
|
|
34
235
|
def test_duplication_with_extension
|
35
|
-
assert_equal File.join(@vroot, 'README copy 1.txt'), ElFinder::Pathname.
|
236
|
+
assert_equal File.join(@vroot, 'README copy 1.txt'), ElFinder::Pathname.new(@vroot,'README.txt').duplicate.fullpath.to_s
|
36
237
|
end
|
37
238
|
|
38
239
|
def test_2nd_duplication_with_extension
|
39
240
|
::FileUtils.touch(File.join(@vroot, 'README copy 1.txt'))
|
40
|
-
assert_equal File.join(@vroot, 'README copy 2.txt'), ElFinder::Pathname.
|
241
|
+
assert_equal File.join(@vroot, 'README copy 2.txt'), ElFinder::Pathname.new(@vroot,'README.txt').duplicate.fullpath.to_s
|
41
242
|
end
|
42
243
|
|
43
244
|
def test_duplication_of_duplication_lookalike
|
44
|
-
assert_equal File.join(@vroot, 'README copy A copy 1.txt'), ElFinder::Pathname.
|
245
|
+
assert_equal File.join(@vroot, 'README copy A copy 1.txt'), ElFinder::Pathname.new(@vroot,'README copy A.txt').duplicate.fullpath.to_s
|
45
246
|
end
|
46
247
|
|
47
248
|
def test_duplication_of_duplication_lookalike2
|
48
|
-
assert_equal File.join(@vroot, 'README copy copy 1.txt'), ElFinder::Pathname.
|
249
|
+
assert_equal File.join(@vroot, 'README copy copy 1.txt'), ElFinder::Pathname.new(@vroot,'README copy.txt').duplicate.fullpath.to_s
|
49
250
|
end
|
50
251
|
|
51
252
|
def test_on_disk_duplication
|
52
|
-
file = ElFinder::Pathname.
|
53
|
-
|
253
|
+
file = ElFinder::Pathname.new(@vroot, 'README.txt')
|
254
|
+
file.touch
|
54
255
|
assert_equal true, File.exist?(File.join(@vroot, 'README.txt'))
|
55
256
|
duplicate = file.duplicate
|
56
|
-
|
257
|
+
duplicate.touch
|
57
258
|
assert_equal true, File.exist?(File.join(@vroot, 'README copy 1.txt'))
|
58
259
|
end
|
59
260
|
|
60
|
-
################################################################################
|
61
|
-
|
62
261
|
def test_rename_on_same_filesystem
|
63
|
-
file = ElFinder::Pathname.
|
64
|
-
|
262
|
+
file = ElFinder::Pathname.new(@vroot, 'old.txt')
|
263
|
+
file.touch
|
65
264
|
assert_equal true, File.exist?(File.join(@vroot, 'old.txt'))
|
66
265
|
file.rename(File.join(@vroot, 'new.txt'))
|
67
266
|
assert_equal false, File.exist?(File.join(@vroot, 'old.txt'))
|
68
267
|
assert_equal true, File.exist?(File.join(@vroot, 'new.txt'))
|
268
|
+
assert_equal 'new.txt', file.path.to_s
|
69
269
|
end
|
70
270
|
|
71
271
|
def test_rename_on_different_filesystem
|
72
272
|
if File.directory?('/Volumes/MyBook')
|
73
|
-
file = ElFinder::Pathname.
|
74
|
-
|
273
|
+
file = ElFinder::Pathname.new(@vroot, 'old.txt')
|
274
|
+
file.touch
|
75
275
|
assert_equal true, File.exist?(File.join(@vroot, 'old.txt'))
|
76
|
-
|
276
|
+
|
277
|
+
File.symlink('/Volumes/MyBook', File.join(@vroot, 'mybook'))
|
278
|
+
assert_equal true, File.symlink?(File.join(@vroot, 'mybook'))
|
279
|
+
assert_equal '/Volumes/MyBook', File.readlink(File.join(@vroot, 'mybook'))
|
280
|
+
|
281
|
+
file.rename('mybook/elfinder.rename.test.safe.to.delete')
|
77
282
|
assert_equal false, File.exist?(File.join(@vroot, 'old.txt'))
|
78
283
|
assert_equal true, File.exist?('/Volumes/MyBook/elfinder.rename.test.safe.to.delete')
|
79
284
|
file.unlink
|
@@ -81,40 +286,4 @@ class TestPathname < Test::Unit::TestCase
|
|
81
286
|
end
|
82
287
|
end
|
83
288
|
|
84
|
-
################################################################################
|
85
|
-
|
86
|
-
def test_basename_without_extension
|
87
|
-
file = ElFinder::Pathname.new_with_root(@vroot, 'foo.txt')
|
88
|
-
assert_respond_to file, :basename_without_extension
|
89
|
-
assert_equal 'foo', file.basename_without_extension.to_s
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_unique_on_create
|
93
|
-
file = ElFinder::Pathname.new_with_root(@vroot, 'foo.txt')
|
94
|
-
assert_equal 'foo.txt', file.unique.basename.to_s
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_unique_conflict
|
98
|
-
file = ElFinder::Pathname.new_with_root(@vroot, 'pjkh.png')
|
99
|
-
assert_equal 'pjkh 1.png', file.unique.basename.to_s
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_unique_conflict_twice
|
103
|
-
FileUtils.touch ElFinder::Pathname.new_with_root(@vroot, 'pjkh 1.png')
|
104
|
-
file = ElFinder::Pathname.new_with_root(@vroot, 'pjkh.png')
|
105
|
-
assert_equal 'pjkh 2.png', file.unique.basename.to_s
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_relative_to_method
|
109
|
-
assert_equal "", ElFinder::Pathname.new_with_root(@vroot).relative_to(::Pathname.new(@vroot)).to_s
|
110
|
-
assert_equal "foo.txt", ElFinder::Pathname.new_with_root(@vroot, 'foo.txt').relative_to(::Pathname.new(@vroot)).to_s
|
111
|
-
assert_equal "foo/bar.txt", ElFinder::Pathname.new_with_root(@vroot, 'foo/bar.txt').relative_to(::Pathname.new(@vroot)).to_s
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_class_type
|
115
|
-
assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo')
|
116
|
-
assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo') + 'bar'
|
117
|
-
assert_kind_of ElFinder::Pathname, ElFinder::Pathname.new_with_root(@vroot, 'foo').join('bar')
|
118
|
-
end
|
119
|
-
|
120
289
|
end
|
data/test/test_el_finder.rb
CHANGED
@@ -69,6 +69,18 @@ class TestElFinder < Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_cwd_name_for_root
|
73
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
74
|
+
assert r[:cwd][:name], 'Home'
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_cwd_name_for_sub_directory
|
78
|
+
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
79
|
+
target = r[:cdc].find{|e| e[:name] == 'foo'}
|
80
|
+
h, r = @elfinder.run(:cmd => 'open', :target => target[:hash])
|
81
|
+
assert r[:cwd][:name], 'Home/foo'
|
82
|
+
end
|
83
|
+
|
72
84
|
def test_mkdir
|
73
85
|
h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
|
74
86
|
h1, r1 = @elfinder.run(:cmd => 'mkdir', :current => r[:cwd][:hash], :name => 'dir1')
|
data/test/test_el_finder_hash.rb
CHANGED
@@ -7,13 +7,13 @@ class TestElFinder < Test::Unit::TestCase
|
|
7
7
|
################################################################################
|
8
8
|
|
9
9
|
def test_to_hash_method
|
10
|
-
assert_equal Base64.encode64('foo/bar').chomp, @elfinder.to_hash(ElFinder::Pathname.
|
11
|
-
assert_equal Base64.encode64('
|
10
|
+
assert_equal Base64.encode64('foo/bar').chomp, @elfinder.to_hash(ElFinder::Pathname.new(@vroot, 'foo/bar'))
|
11
|
+
assert_equal Base64.encode64('.').chomp, @elfinder.to_hash(ElFinder::Pathname.new(@vroot))
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_from_hash_method
|
15
15
|
assert_equal File.join(@vroot, 'foo/bar'), @elfinder.from_hash(Base64.encode64('foo/bar').chomp).to_s
|
16
|
-
assert_equal @vroot, @elfinder.from_hash(Base64.encode64('').chomp).to_s
|
16
|
+
assert_equal @vroot, @elfinder.from_hash(Base64.encode64('.').chomp).to_s
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
@@ -51,8 +51,6 @@ class TestElFinderSymlink < Test::Unit::TestCase
|
|
51
51
|
h, r = @elfinder.run(:cmd => 'open', :target => foo[:hash])
|
52
52
|
source = r[:cdc].find{|e| e[:name] == 'tom.txt'}
|
53
53
|
|
54
|
-
pp source
|
55
|
-
pp target
|
56
54
|
|
57
55
|
assert_equal source[:hash], target[:link]
|
58
56
|
assert_equal 'foo/tom.txt', target[:linkTo]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: el_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 7
|
10
|
+
version: 1.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philip Hallstrom
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-12 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|