recls-ruby 2.11.0.3 → 2.12.0
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.
- checksums.yaml +4 -4
- data/LICENSE +24 -27
- data/README.md +1 -242
- data/examples/find_files_and_directories.md +30 -33
- data/examples/find_files_and_directories.recursive.md +254 -255
- data/examples/show_hidden_files.md +1 -4
- data/examples/show_hidden_files.rb +1 -1
- data/examples/show_readonly_files.md +1 -4
- data/examples/show_readonly_files.rb +1 -1
- data/lib/recls/api.rb +73 -76
- data/lib/recls/combine_paths_1.rb +23 -26
- data/lib/recls/combine_paths_2plus.rb +29 -32
- data/lib/recls/entry.rb +273 -277
- data/lib/recls/file_search.rb +193 -194
- data/lib/recls/flags.rb +45 -48
- data/lib/recls/foreach.rb +98 -105
- data/lib/recls/obsolete.rb +79 -80
- data/lib/recls/recls.rb +22 -16
- data/lib/recls/stat.rb +134 -137
- data/lib/recls/util.rb +92 -95
- data/lib/recls/version.rb +17 -22
- data/lib/recls/ximpl/os.rb +44 -46
- data/lib/recls/ximpl/unix.rb +35 -39
- data/lib/recls/ximpl/util.rb +596 -598
- data/lib/recls/ximpl/windows.rb +137 -141
- data/lib/recls.rb +9 -10
- 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 +7 -7
data/lib/recls/stat.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
#
|
2
|
-
# File:
|
1
|
+
# ######################################################################### #
|
2
|
+
# File: recls/stat.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: Defines the Recls.stat() method for the recls.Ruby library.
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 24th July 2012
|
7
|
+
# Updated: 14th March 2019
|
8
8
|
#
|
9
|
-
# Author:
|
9
|
+
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
12
11
|
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
13
12
|
# All rights reserved.
|
14
13
|
#
|
@@ -34,149 +33,147 @@
|
|
34
33
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35
34
|
# POSSIBILITY OF SUCH DAMAGE.
|
36
35
|
#
|
37
|
-
#
|
36
|
+
# ######################################################################### #
|
38
37
|
|
39
38
|
|
40
39
|
require 'recls/entry'
|
41
40
|
require 'recls/flags'
|
42
41
|
|
43
|
-
|
44
42
|
=begin
|
45
43
|
=end
|
46
44
|
|
47
|
-
# @!visibility private
|
48
45
|
class Object; end # :nodoc:
|
49
46
|
|
50
47
|
module Recls
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
49
|
+
# Equivalent to a Recls::stat() but only returns (a non-+nil+ value) if the
|
50
|
+
# path exists _and_ represents a directory
|
51
|
+
#
|
52
|
+
# This has two advantages over +File.directory?+: it obtains a
|
53
|
+
# Recls::Entry in the case where the path represents a directory; and
|
54
|
+
# it does '~' interpretation
|
55
|
+
#
|
56
|
+
# === Signature
|
57
|
+
#
|
58
|
+
# * *Parameters:*
|
59
|
+
# - +path+ (String, Recls::Entry) The path
|
60
|
+
#
|
61
|
+
# === Return
|
62
|
+
# (Recls::Entry, nil) The entry if +path+ exists and is a directory; +nil+ otherwise
|
63
|
+
def self.directory?(path, *args)
|
64
|
+
|
65
|
+
fe = self.stat(path, *args)
|
66
|
+
|
67
|
+
if fe
|
68
|
+
|
69
|
+
return nil unless fe.directory?
|
70
|
+
end
|
71
|
+
|
72
|
+
fe
|
73
|
+
end
|
74
|
+
|
75
|
+
# Equivalent to a Recls::stat() but only returns (a non-+nil+ value) if the
|
76
|
+
# path exists _and_ represents a file
|
77
|
+
#
|
78
|
+
# This has two advantages over +File.file?+: it obtains a
|
79
|
+
# Recls::Entry in the case where the path represents a file; and
|
80
|
+
# it does '~' interpretation
|
81
|
+
#
|
82
|
+
# === Signature
|
83
|
+
#
|
84
|
+
# * *Parameters:*
|
85
|
+
# - +path+ (String, Recls::Entry) The path
|
86
|
+
#
|
87
|
+
# === Return
|
88
|
+
# (Recls::Entry, nil) The entry if +path+ exists and is a file; +nil+ otherwise
|
89
|
+
def self.file?(path, *args)
|
90
|
+
|
91
|
+
fe = self.stat(path, *args)
|
92
|
+
|
93
|
+
if fe
|
94
|
+
|
95
|
+
return nil unless fe.file?
|
96
|
+
end
|
97
|
+
|
98
|
+
fe
|
99
|
+
end
|
100
|
+
|
101
|
+
# Obtains a single Recls::Entry instance from a path, according to the
|
102
|
+
# given arguments, which can be any combination of search-root and
|
103
|
+
# flags, as discussed below
|
104
|
+
#
|
105
|
+
# === Signature
|
106
|
+
#
|
107
|
+
# * *Parameters:*
|
108
|
+
# - +path+ (String) A path to evaluate. May not be +nil+
|
109
|
+
# - +search_root+ (String, Recls::Entry) A directory from which the returned Entry instance's search-relative attributes are evaluated
|
110
|
+
# - +flags+ (Integer) A bit-combined set of flags (such as Recls::DIRECTORIES, Recls::FILES, Recls::RECURSIVE, Recls::DETAILS_LATER, and so on)
|
111
|
+
#
|
112
|
+
# ==== Parameter Ordering
|
113
|
+
#
|
114
|
+
# The parameters may be expressed in any of the following permutations:
|
115
|
+
# - +path+
|
116
|
+
# - +path+, +flags+
|
117
|
+
# - +path+, +search_root+
|
118
|
+
# - +path+, +flags+, +search_root+
|
119
|
+
# - +path+, +search_root+, +flags+
|
120
|
+
#
|
121
|
+
# === Return
|
122
|
+
# (Recls::Entry) An entry representing the path on the file-system, or
|
123
|
+
# +nil+ if the path does not refer to an existing entity. If the
|
124
|
+
# Recls::DETAILS_LATER flag is included, then an entry is returned
|
125
|
+
# regardless of its existence
|
126
|
+
def self.stat(path, *args)
|
127
|
+
|
128
|
+
flags = 0
|
129
|
+
search_root = nil
|
130
|
+
message = nil
|
131
|
+
|
132
|
+
path = File.expand_path(path) if path =~ /^~[\\\/]*/
|
133
|
+
|
134
|
+
case args.size
|
135
|
+
when 0
|
136
|
+
|
137
|
+
;
|
138
|
+
when 1
|
139
|
+
|
140
|
+
case args[0]
|
141
|
+
when ::Integer
|
142
|
+
|
143
|
+
flags = args[0]
|
144
|
+
when ::String
|
145
|
+
|
146
|
+
search_root = args[0]
|
147
|
+
else
|
148
|
+
|
149
|
+
message = "argument '#{args[0]}' (#{args[0].class}) not valid"
|
150
|
+
end
|
151
|
+
when 2
|
152
|
+
|
153
|
+
if false
|
154
|
+
elsif ::Integer === args[0] && ::String === args[1]
|
155
|
+
|
156
|
+
flags = args[0]
|
157
|
+
search_root = args[1]
|
158
|
+
elsif ::String === args[0] && ::Integer === args[1]
|
159
|
+
|
160
|
+
search_root = args[0]
|
161
|
+
flags = args[1]
|
162
|
+
else
|
163
|
+
|
164
|
+
message = "invalid combination of arguments"
|
165
|
+
end
|
166
|
+
else
|
167
|
+
|
168
|
+
message = "too many arguments"
|
169
|
+
end
|
170
|
+
|
171
|
+
raise ArgumentError, "#{message}: Recls.stat() takes one (path), two (path+flags or path+search_root), or three (path+search_root+flags) arguments" if message
|
172
|
+
|
173
|
+
Recls::Ximpl.stat_prep(path, search_root, flags)
|
174
|
+
end
|
178
175
|
end # module Recls
|
179
176
|
|
180
|
-
|
181
177
|
# ############################## end of file ############################# #
|
182
178
|
|
179
|
+
|
data/lib/recls/util.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
#
|
2
|
-
# File:
|
1
|
+
# ######################################################################### #
|
2
|
+
# File: recls/util.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: Utility module functions for recls library
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 17th February 2014
|
7
|
+
# Updated: 14th April 2019
|
8
8
|
#
|
9
|
-
# Author:
|
9
|
+
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
12
11
|
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
13
12
|
# All rights reserved.
|
14
13
|
#
|
@@ -34,118 +33,116 @@
|
|
34
33
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35
34
|
# POSSIBILITY OF SUCH DAMAGE.
|
36
35
|
#
|
37
|
-
#
|
36
|
+
# ######################################################################### #
|
38
37
|
|
39
38
|
|
40
39
|
require 'recls/stat'
|
41
40
|
require 'recls/ximpl/util'
|
42
41
|
require 'recls/ximpl/os'
|
43
42
|
|
44
|
-
|
45
43
|
=begin
|
46
44
|
=end
|
47
45
|
|
48
|
-
# @!visibility private
|
49
46
|
class Object; end # :nodoc:
|
50
47
|
|
51
48
|
module Recls
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
50
|
+
# Obtains the absolute form of the given path
|
51
|
+
#
|
52
|
+
# === Signature
|
53
|
+
#
|
54
|
+
# * *Parameters:*
|
55
|
+
# - +path+ (String, Recls::Entry) The path
|
56
|
+
#
|
57
|
+
# === Return
|
58
|
+
# (String) The absolute form of the path
|
59
|
+
def self.absolute_path(path)
|
60
|
+
|
61
|
+
return path.path if 'Recls::Entry' === path.class.to_s
|
62
|
+
|
63
|
+
Recls::Ximpl.absolute_path path
|
64
|
+
end
|
65
|
+
|
66
|
+
# Canonicalises the given path, by removing dots ('.' and '..')
|
67
|
+
# directories
|
68
|
+
#
|
69
|
+
# === Signature
|
70
|
+
#
|
71
|
+
# * *Parameters:*
|
72
|
+
# - +path+ (String, Recls::Entry) The path
|
73
|
+
#
|
74
|
+
# === Return
|
75
|
+
# (String) The canonical form of the path
|
76
|
+
def self.canonicalise_path(path)
|
77
|
+
|
78
|
+
path = path.path if 'Recls::Entry' === path.class.to_s
|
79
|
+
|
80
|
+
Recls::Ximpl.canonicalise_path path
|
81
|
+
end
|
82
|
+
|
83
|
+
# Derives a given path relative to an origin, unless the path is
|
84
|
+
# absolute
|
85
|
+
#
|
86
|
+
# === Signature
|
87
|
+
#
|
88
|
+
# * *Parameters:*
|
89
|
+
# - +origin+ (String, Recls::Entry) The path against which +path+ will be evaluated
|
90
|
+
# - +path+ (String, Recls::Entry) The path to evaluate
|
91
|
+
#
|
92
|
+
# === Return
|
93
|
+
# (String) The relative form of the path
|
94
|
+
def self.derive_relative_path(origin, path)
|
95
|
+
|
96
|
+
Recls::Ximpl.derive_relative_path origin, path
|
97
|
+
end
|
101
98
|
end # module Recls
|
102
99
|
|
103
100
|
if RUBY_VERSION >= '2'
|
104
101
|
|
105
|
-
|
102
|
+
require 'recls/combine_paths_2plus'
|
106
103
|
else
|
107
104
|
|
108
|
-
|
105
|
+
require 'recls/combine_paths_1'
|
109
106
|
end
|
110
107
|
|
111
108
|
module Recls
|
112
109
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
110
|
+
# Indicates whether the given path exists, obtaining a Recls::Entry
|
111
|
+
# instance if so
|
112
|
+
#
|
113
|
+
# === Signature
|
114
|
+
#
|
115
|
+
# * *Parameters:*
|
116
|
+
# - +path+ (String, Recls::Entry) The path
|
117
|
+
#
|
118
|
+
# === Return
|
119
|
+
# (Recls::Entry, nil) The entry if +path+ exists; +nil+ otherwise
|
120
|
+
def self.exist?(path)
|
121
|
+
|
122
|
+
return nil if path.nil?
|
123
|
+
|
124
|
+
Recls.stat(path)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Indicates whether the given path is absolute
|
128
|
+
#
|
129
|
+
# === Signature
|
130
|
+
#
|
131
|
+
# * *Parameters:*
|
132
|
+
# - +path+ (String, Recls::Entry) The path
|
133
|
+
#
|
134
|
+
# === Return
|
135
|
+
# (boolean) +true+ if +path+ is absolute; +false+ otherwise
|
136
|
+
def self.absolute_path?(path)
|
137
|
+
|
138
|
+
return nil if path.nil?
|
139
|
+
|
140
|
+
return true if 'Recls::Entry' === path.class.to_s
|
141
|
+
|
142
|
+
Recls::Ximpl.absolute_path? path
|
143
|
+
end
|
147
144
|
end # module Recls
|
148
145
|
|
149
|
-
|
150
146
|
# ############################## end of file ############################# #
|
151
147
|
|
148
|
+
|
data/lib/recls/version.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#
|
2
|
-
# File:
|
1
|
+
# ######################################################################### #
|
2
|
+
# File: recls/version.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: Version for recls library
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 14th February 2014
|
7
|
+
# Updated: 6th April 2021
|
8
8
|
#
|
9
|
-
# Author:
|
9
|
+
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2019-
|
11
|
+
# Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
|
12
12
|
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
13
13
|
# All rights reserved.
|
14
14
|
#
|
@@ -34,32 +34,27 @@
|
|
34
34
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35
35
|
# POSSIBILITY OF SUCH DAMAGE.
|
36
36
|
#
|
37
|
-
#
|
37
|
+
# ######################################################################### #
|
38
38
|
|
39
39
|
|
40
40
|
=begin
|
41
41
|
=end
|
42
42
|
|
43
|
-
# @!visibility private
|
44
43
|
class Object; end # :nodoc:
|
45
44
|
|
46
45
|
module Recls
|
47
46
|
|
48
|
-
|
49
|
-
|
47
|
+
# Current version of the recls.Ruby library
|
48
|
+
VERSION = '2.12.0'
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# @!visibility private
|
58
|
-
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
59
|
-
# @!visibility private
|
60
|
-
VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
|
50
|
+
private
|
51
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
52
|
+
public
|
53
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
54
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
55
|
+
VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
|
61
56
|
end # module Recls
|
62
57
|
|
63
|
-
|
64
58
|
# ############################## end of file ############################# #
|
65
59
|
|
60
|
+
|