recls-ruby 2.11.0 → 2.11.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +27 -24
- data/README.md +242 -1
- data/examples/find_files_and_directories.md +33 -30
- data/examples/find_files_and_directories.recursive.md +255 -254
- data/examples/show_hidden_files.md +4 -1
- data/examples/show_hidden_files.rb +1 -1
- data/examples/show_readonly_files.md +4 -1
- data/examples/show_readonly_files.rb +1 -1
- data/lib/recls/api.rb +76 -73
- data/lib/recls/combine_paths_1.rb +26 -23
- data/lib/recls/combine_paths_2plus.rb +32 -29
- data/lib/recls/entry.rb +277 -273
- data/lib/recls/file_search.rb +194 -193
- data/lib/recls/flags.rb +47 -45
- data/lib/recls/foreach.rb +105 -98
- data/lib/recls/obsolete.rb +80 -79
- data/lib/recls/recls.rb +16 -15
- data/lib/recls/stat.rb +137 -134
- data/lib/recls/util.rb +95 -92
- data/lib/recls/version.rb +18 -17
- data/lib/recls/ximpl/os.rb +45 -43
- data/lib/recls/ximpl/unix.rb +38 -35
- data/lib/recls/ximpl/util.rb +597 -596
- data/lib/recls/ximpl/windows.rb +139 -136
- data/lib/recls.rb +10 -9
- data/test/scratch/test_display_parts.rb +33 -33
- data/test/scratch/test_entry.rb +6 -6
- data/test/scratch/test_files_and_directories.rb +8 -8
- data/test/scratch/test_foreach.rb +10 -10
- data/test/scratch/test_module_function.rb +33 -33
- data/test/scratch/test_pattern_arrays.rb +5 -5
- data/test/scratch/test_show_dev_and_ino.rb +1 -1
- data/test/scratch/test_show_hidden.rb +3 -3
- data/test/unit/tc_recls_entries.rb +31 -31
- data/test/unit/tc_recls_entry.rb +19 -19
- data/test/unit/tc_recls_file_search.rb +32 -32
- data/test/unit/tc_recls_module.rb +25 -25
- data/test/unit/tc_recls_util.rb +161 -161
- data/test/unit/tc_recls_ximpl_util.rb +676 -676
- data/test/unit/test_all_separately.sh +1 -1
- data/test/unit/ts_all.rb +4 -4
- metadata +6 -6
@@ -6,9 +6,9 @@ $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
|
6
6
|
|
7
7
|
require 'recls'
|
8
8
|
|
9
|
-
root_dir
|
10
|
-
patterns_a
|
11
|
-
patterns_s
|
9
|
+
root_dir = File.join(File.dirname(__FILE__), '../..')
|
10
|
+
patterns_a = %w{ *.rb *.md }
|
11
|
+
patterns_s = patterns_a.join('|')
|
12
12
|
|
13
13
|
|
14
14
|
puts
|
@@ -16,7 +16,7 @@ puts "Searching for pattern string '#{patterns_s}':"
|
|
16
16
|
|
17
17
|
Recls::FileSearch.new(root_dir, patterns_s, Recls::FILES | Recls::RECURSIVE).each do |fe|
|
18
18
|
|
19
|
-
|
19
|
+
puts fe.search_relative_path
|
20
20
|
end
|
21
21
|
|
22
22
|
|
@@ -26,7 +26,7 @@ puts "Searching for pattern array '#{patterns_a}':"
|
|
26
26
|
|
27
27
|
Recls::FileSearch.new(root_dir, patterns_a, Recls::FILES | Recls::RECURSIVE).each do |fe|
|
28
28
|
|
29
|
-
|
29
|
+
puts fe.search_relative_path
|
30
30
|
end
|
31
31
|
|
32
32
|
|
@@ -8,6 +8,6 @@ require 'recls'
|
|
8
8
|
|
9
9
|
Recls::FileSearch.new('.', Recls::WILDCARDS_ALL, Recls::FILES | Recls::RECURSIVE).each do |fe|
|
10
10
|
|
11
|
-
|
11
|
+
puts "#{fe.search_relative_path}\t#{fe.dev}\t#{fe.ino}\t#{fe.nlink}"
|
12
12
|
end
|
13
13
|
|
@@ -10,14 +10,14 @@ puts
|
|
10
10
|
puts "Hidden directories:"
|
11
11
|
Recls.file_rsearch(nil, nil, Recls::DIRECTORIES | Recls::SHOW_HIDDEN).each do |fe|
|
12
12
|
|
13
|
-
|
13
|
+
puts "\t#{fe.search_relative_path}" if fe.hidden?
|
14
14
|
end
|
15
15
|
|
16
16
|
puts
|
17
17
|
puts "Hidden files:"
|
18
18
|
Recls.file_search(nil, nil, Recls::RECURSIVE | Recls::FILES | Recls::SHOW_HIDDEN).each do |fe|
|
19
19
|
|
20
|
-
|
20
|
+
puts "\t#{fe.search_relative_path}" if fe.hidden?
|
21
21
|
end
|
22
22
|
|
23
23
|
|
@@ -25,6 +25,6 @@ puts
|
|
25
25
|
puts "Hidden directories & files:"
|
26
26
|
Recls.file_search(nil, nil, Recls::RECURSIVE | Recls::DIRECTORIES | Recls::FILES | Recls::MARK_DIRECTORIES | Recls::SHOW_HIDDEN).each do |fe|
|
27
27
|
|
28
|
-
|
28
|
+
puts "\t#{fe.search_relative_path}" if fe.hidden?
|
29
29
|
end
|
30
30
|
|
@@ -1,55 +1,55 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# test Recls entries
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
7
|
-
|
8
7
|
require 'recls'
|
9
8
|
|
10
9
|
require 'test/unit'
|
11
10
|
|
11
|
+
|
12
12
|
class Test_Recls_entries < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
unless defined? assert_false
|
15
|
+
def assert_false arg0, *args
|
16
|
+
assert !arg0, *args
|
17
|
+
end
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
def test_entries_in_directory_have_unique_names
|
21
21
|
|
22
|
-
|
22
|
+
entries = Recls::FileSearch.new('~', Recls::WILDCARDS_ALL, Recls::FILES).to_a
|
23
23
|
|
24
|
-
|
24
|
+
hashed_entries = Hash[entries.each_with_index.map { |fe, index| [ fe, index] }]
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
# ensure that no duplicates in hash (and hence Entry.hash and Entry.<=> work)
|
27
|
+
assert_equal entries.size, hashed_entries.size
|
28
28
|
|
29
|
-
|
29
|
+
entries.each_with_index do |entry, index|
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
entry_a = entries[index]
|
32
|
+
entry_b = Recls.stat(entries[index].path)
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# ensure that different entry instances representing the same path evaluate
|
35
|
+
# equal (and hence Entry.eq? and Entry.== work)
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
assert entry_a.eql? entry_a
|
38
|
+
assert entry_a.eql? entry_b
|
39
|
+
assert_false entry_a.eql? entry_a.path
|
40
|
+
assert_false entry_a.eql? entry_b.path
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
assert_equal entry_a, entry_a
|
43
|
+
assert_equal entry_a, entry_b
|
44
|
+
assert_equal entry_a, entry_a.path
|
45
|
+
assert_equal entry_a, entry_b.path
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
assert_same entry_a, entries[index]
|
48
|
+
assert_not_same entry_a, entry_b
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
assert_equal index, hashed_entries[entry_a]
|
51
|
+
assert_equal index, hashed_entries[entry_b]
|
52
|
+
end
|
53
|
+
end
|
54
54
|
end
|
55
55
|
|
data/test/unit/tc_recls_entry.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# test Recls entries
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
7
|
-
|
8
7
|
require 'recls'
|
9
8
|
|
10
9
|
require 'test/unit'
|
11
10
|
|
11
|
+
|
12
12
|
class Test_Recls_entry < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
unless defined? assert_false
|
15
|
+
def assert_false arg0, *args
|
16
|
+
assert !arg0, *args
|
17
|
+
end
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
def setup
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
@cwd = Dir.pwd
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
def test_entry_does_not_mark_directory
|
26
26
|
|
27
|
-
|
27
|
+
cwd = Recls.stat @cwd
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
assert_equal @cwd, cwd.path
|
30
|
+
end
|
31
31
|
|
32
|
-
|
32
|
+
def test_entry_does_mark_directory
|
33
33
|
|
34
|
-
|
34
|
+
cwd = Recls.stat @cwd, Recls::MARK_DIRECTORIES
|
35
35
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
36
|
+
# assert_equal "#{@cwd}#{Recls::PATH_NAME_SEPARATOR}", cwd.path
|
37
|
+
assert_equal "#{@cwd}/", cwd.path
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
@@ -4,65 +4,65 @@
|
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
7
|
-
|
8
7
|
require 'recls'
|
9
8
|
|
10
9
|
require 'test/unit'
|
11
10
|
|
11
|
+
|
12
12
|
class Test_Recls_FileSearch_class < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
14
|
+
def test_construction
|
15
15
|
|
16
|
-
|
16
|
+
fs = Recls::FileSearch.new(nil, nil, 0)
|
17
17
|
|
18
|
-
|
18
|
+
assert_not_nil(fs)
|
19
19
|
|
20
|
-
|
20
|
+
end # def test_construction
|
21
21
|
|
22
|
-
|
22
|
+
def test_construction_1
|
23
23
|
|
24
|
-
|
24
|
+
fs = Recls::FileSearch.new('abc', '*c', Recls::FILES)
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
assert_not_nil(fs)
|
27
|
+
assert_equal('abc', fs.search_root)
|
28
|
+
assert_equal(['*c'], fs.patterns)
|
29
29
|
if not defined? RECLS_NO_OBSOLETE
|
30
|
-
|
31
|
-
|
30
|
+
assert_equal('abc', fs.searchRoot)
|
31
|
+
assert_equal(['*c'], fs.pattern)
|
32
32
|
end
|
33
|
-
|
33
|
+
assert_equal(Recls::FILES, fs.flags)
|
34
34
|
|
35
|
-
|
35
|
+
end # def test_construction_1
|
36
36
|
|
37
|
-
|
37
|
+
def test_construction_2
|
38
38
|
|
39
|
-
|
39
|
+
fs = Recls::FileSearch.new('def', '*c', 0)
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
assert_not_nil(fs)
|
42
|
+
assert_equal('def', fs.search_root)
|
43
|
+
assert_equal(['*c'], fs.patterns)
|
44
44
|
if not defined? RECLS_NO_OBSOLETE
|
45
|
-
|
46
|
-
|
45
|
+
assert_equal('def', fs.searchRoot)
|
46
|
+
assert_equal(['*c'], fs.pattern)
|
47
47
|
end
|
48
|
-
|
48
|
+
assert_equal(Recls::FILES, fs.flags)
|
49
49
|
|
50
|
-
|
50
|
+
end # def test_construction_2
|
51
51
|
|
52
|
-
|
52
|
+
def test_construction_3
|
53
53
|
|
54
|
-
|
54
|
+
fs = Recls::FileSearch.new('ghi', '*c', Recls::DIRECTORIES)
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
assert_not_nil(fs)
|
57
|
+
assert_equal('ghi', fs.search_root)
|
58
|
+
assert_equal(['*c'], fs.patterns)
|
59
59
|
if not defined? RECLS_NO_OBSOLETE
|
60
|
-
|
61
|
-
|
60
|
+
assert_equal('ghi', fs.searchRoot)
|
61
|
+
assert_equal(['*c'], fs.pattern)
|
62
62
|
end
|
63
|
-
|
63
|
+
assert_equal(Recls::DIRECTORIES, fs.flags)
|
64
64
|
|
65
|
-
|
65
|
+
end # def test_construction_3
|
66
66
|
|
67
67
|
end
|
68
68
|
|
@@ -4,72 +4,72 @@
|
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
7
|
-
|
8
7
|
require 'recls'
|
9
8
|
|
10
9
|
require 'test/unit'
|
11
10
|
|
11
|
+
|
12
12
|
class Test_Recls_constants < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
private
|
15
|
+
@@OS_IS_WINDOWS = Recls::Ximpl::OS::OS_IS_WINDOWS
|
16
16
|
|
17
|
-
|
17
|
+
public
|
18
18
|
|
19
19
|
|
20
|
-
|
20
|
+
def test_PATH_NAME_SEPARATOR
|
21
21
|
|
22
|
-
|
22
|
+
expected = @@OS_IS_WINDOWS ? '\\' : '/'
|
23
23
|
|
24
|
-
|
24
|
+
assert_equal(expected, Recls::PATH_NAME_SEPARATOR)
|
25
25
|
|
26
|
-
|
26
|
+
end # def test_PATH_NAME_SEPARATOR
|
27
27
|
|
28
28
|
if not defined? RECLS_NO_OBSOLETE
|
29
29
|
|
30
|
-
|
30
|
+
def test_pathNameSeparator
|
31
31
|
|
32
|
-
|
32
|
+
assert_equal(Recls::PATH_NAME_SEPARATOR, Recls::pathNameSeparator)
|
33
33
|
|
34
|
-
|
34
|
+
end # def test_pathNameSeparator
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
def test_PATH_SEPARATOR
|
39
39
|
|
40
|
-
|
40
|
+
expected = @@OS_IS_WINDOWS ? ';' : ':'
|
41
41
|
|
42
|
-
|
42
|
+
assert_equal(expected, Recls::PATH_SEPARATOR)
|
43
43
|
|
44
|
-
|
44
|
+
end # def test_PATH_SEPARATOR
|
45
45
|
|
46
46
|
if not defined? RECLS_NO_OBSOLETE
|
47
47
|
|
48
|
-
|
48
|
+
def test_pathSeparator
|
49
49
|
|
50
|
-
|
50
|
+
assert_equal(Recls::PATH_SEPARATOR, Recls::pathSeparator)
|
51
51
|
|
52
|
-
|
52
|
+
end # def test_pathSeparator
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
56
|
|
57
57
|
|
58
|
-
|
58
|
+
def test_WILDCARDS_ALL
|
59
59
|
|
60
|
-
|
60
|
+
#expected = @@OS_IS_WINDOWS ? '*.*' : '*'
|
61
61
|
|
62
|
-
|
62
|
+
assert_equal('*', Recls::WILDCARDS_ALL)
|
63
63
|
|
64
|
-
|
64
|
+
end # def test_WILDCARDS_ALL
|
65
65
|
|
66
66
|
if not defined? RECLS_NO_OBSOLETE
|
67
67
|
|
68
|
-
|
68
|
+
def test_wildcardsAll
|
69
69
|
|
70
|
-
|
70
|
+
assert_equal(Recls::WILDCARDS_ALL, Recls::wildcardsAll)
|
71
71
|
|
72
|
-
|
72
|
+
end # def test_wildcardsAll
|
73
73
|
|
74
74
|
end
|
75
75
|
|