recls-ruby 2.9.1 → 2.10.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 +5 -5
- data/lib/recls/api.rb +20 -35
- data/lib/recls/combine_paths_1.rb +8 -4
- data/lib/recls/combine_paths_2plus.rb +12 -13
- data/lib/recls/entry.rb +35 -4
- data/lib/recls/file_search.rb +21 -21
- data/lib/recls/flags.rb +20 -4
- data/lib/recls/foreach.rb +38 -6
- data/lib/recls/obsolete.rb +99 -0
- data/lib/recls/recls.rb +27 -56
- data/lib/recls/stat.rb +71 -28
- data/lib/recls/util.rb +71 -4
- data/lib/recls/version.rb +8 -3
- data/lib/recls/ximpl/os.rb +16 -13
- data/lib/recls/ximpl/unix.rb +15 -12
- data/lib/recls/ximpl/util.rb +81 -17
- data/lib/recls/ximpl/windows.rb +18 -13
- data/test/unit/tc_recls_ximpl_util.rb +107 -101
- metadata +7 -6
data/lib/recls/foreach.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Definition of Recls::foreach() utility function
|
5
5
|
#
|
6
6
|
# Created: 22nd October 2014
|
7
|
-
# Updated:
|
7
|
+
# Updated: 14th April 2019
|
8
8
|
#
|
9
9
|
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2012-
|
11
|
+
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
12
12
|
# All rights reserved.
|
13
13
|
#
|
14
14
|
# Redistribution and use in source and binary forms, with or without
|
@@ -38,10 +38,15 @@
|
|
38
38
|
|
39
39
|
require 'recls/file_search'
|
40
40
|
|
41
|
+
=begin
|
42
|
+
=end
|
43
|
+
|
44
|
+
class Object; end # :nodoc:
|
45
|
+
|
41
46
|
module Recls
|
42
47
|
|
43
48
|
private
|
44
|
-
class FileSearchLineEnumerator
|
49
|
+
class FileSearchLineEnumerator # :nodoc: all
|
45
50
|
|
46
51
|
include Enumerable
|
47
52
|
|
@@ -54,7 +59,7 @@ module Recls
|
|
54
59
|
|
55
60
|
@fs.each do |fe|
|
56
61
|
|
57
|
-
IO
|
62
|
+
IO.readlines(fe).each_with_index do |line, index|
|
58
63
|
|
59
64
|
case block.arity
|
60
65
|
when 1
|
@@ -69,9 +74,36 @@ module Recls
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
72
|
-
end
|
77
|
+
end # class FileSearchLineEnumerator
|
73
78
|
public
|
74
79
|
|
80
|
+
# Performs a recursive search and enumerates the lines of all files
|
81
|
+
# found
|
82
|
+
#
|
83
|
+
# === Signature
|
84
|
+
#
|
85
|
+
# * *Parameters:*
|
86
|
+
# - +searchable+ A searchable instance obtained from Recls::file_search() or Recls::file_rsearch()
|
87
|
+
# - +search_root+ (String, Recls::Entry) The root directory of the search. May be +nil+, in which case the current directory is assumed
|
88
|
+
# - +patterns+ (String, Array) The pattern(s) for which to search. May be +nil+, in which case Recls::WILDCARDS_ALL is assumed
|
89
|
+
# - +options+ (Hash) An options hash
|
90
|
+
# - +flags+ (Integer) Combination of flags (with behaviour as described below for the +flags+ option)
|
91
|
+
#
|
92
|
+
# * *Block:*
|
93
|
+
# An optional block that will be executed once for each line in each file
|
94
|
+
# found, where the block must take 1, 2, or 3 parameters, representing the
|
95
|
+
# line [ + file-line-index [ + entry ]]. If no block is given, an
|
96
|
+
# enumerator is returned.
|
97
|
+
#
|
98
|
+
# ==== Parameter Ordering
|
99
|
+
#
|
100
|
+
# The parameters may be expressed in any of the following permutations:
|
101
|
+
# - +searchable+
|
102
|
+
# - +search_root+, +patterns+, +flags+
|
103
|
+
# - +search_root+, +patterns+, +options+
|
104
|
+
#
|
105
|
+
# === Return
|
106
|
+
#
|
75
107
|
def self.foreach(*args, &block)
|
76
108
|
|
77
109
|
fs = nil
|
@@ -97,7 +129,7 @@ module Recls
|
|
97
129
|
return FileSearchLineEnumerator.new(fs)
|
98
130
|
end
|
99
131
|
end
|
100
|
-
end
|
132
|
+
end # module Recls
|
101
133
|
|
102
134
|
# ############################## end of file ############################# #
|
103
135
|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# ######################################################################### #
|
2
|
+
# File: recls/obsolete.rb
|
3
|
+
#
|
4
|
+
# Purpose: Obsolete elements
|
5
|
+
#
|
6
|
+
# Created: 19th July 2012
|
7
|
+
# Updated: 14th April 2019
|
8
|
+
#
|
9
|
+
# Author: Matthew Wilson
|
10
|
+
#
|
11
|
+
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
12
|
+
# All rights reserved.
|
13
|
+
#
|
14
|
+
# Redistribution and use in source and binary forms, with or without
|
15
|
+
# modification, are permitted provided that the following conditions are met:
|
16
|
+
#
|
17
|
+
# * Redistributions of source code must retain the above copyright notice,
|
18
|
+
# this list of conditions and the following disclaimer.
|
19
|
+
#
|
20
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
21
|
+
# this list of conditions and the following disclaimer in the documentation
|
22
|
+
# and/or other materials provided with the distribution.
|
23
|
+
#
|
24
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
27
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
28
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
29
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
30
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
31
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
32
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
33
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
#
|
36
|
+
# ######################################################################### #
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
# ######################################################################### #
|
41
|
+
# Obsolete symbols
|
42
|
+
|
43
|
+
if not defined? RECLS_NO_OBSOLETE
|
44
|
+
|
45
|
+
module Recls # :nodoc: all
|
46
|
+
|
47
|
+
def self.pathNameSeparator
|
48
|
+
|
49
|
+
PATH_NAME_SEPARATOR
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.pathSeparator
|
53
|
+
|
54
|
+
PATH_SEPARATOR
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.wildcardsAll
|
58
|
+
|
59
|
+
WILDCARDS_ALL
|
60
|
+
end
|
61
|
+
|
62
|
+
class FileSearch # :nodoc:
|
63
|
+
|
64
|
+
alias_method :searchRoot, :search_root
|
65
|
+
alias_method :pattern, :patterns
|
66
|
+
end
|
67
|
+
|
68
|
+
class Entry # :nodoc:
|
69
|
+
|
70
|
+
alias_method :uncDrive, :drive
|
71
|
+
alias_method :directoryPath, :directory_path
|
72
|
+
alias_method :directoryParts, :directory_parts
|
73
|
+
alias_method :file, :file_full_name
|
74
|
+
alias_method :shortFile, :file_short_name
|
75
|
+
alias_method :fileBaseName, :file_name_only
|
76
|
+
alias_method :fileName, :file_name_only
|
77
|
+
alias_method :fileExt, :file_extension
|
78
|
+
alias_method :searchDirectory, :search_directory
|
79
|
+
alias_method :searchRelativePath, :search_relative_path
|
80
|
+
|
81
|
+
alias_method :isDirectory, :directory?
|
82
|
+
alias_method :isFile, :file?
|
83
|
+
#alias_method :isLink, :link?
|
84
|
+
alias_method :isReadOnly, :readonly?
|
85
|
+
def isUNC
|
86
|
+
|
87
|
+
d = drive
|
88
|
+
|
89
|
+
d and d.size > 2
|
90
|
+
end
|
91
|
+
|
92
|
+
alias_method :creationTime, :modification_time
|
93
|
+
end
|
94
|
+
end # module Recls
|
95
|
+
end
|
96
|
+
|
97
|
+
# ############################## end of file ############################# #
|
98
|
+
|
99
|
+
|
data/lib/recls/recls.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Main source file for recls library
|
5
5
|
#
|
6
6
|
# Created: 19th July 2012
|
7
|
-
# Updated:
|
7
|
+
# Updated: 14th April 2019
|
8
8
|
#
|
9
9
|
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2012-
|
11
|
+
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
12
12
|
# All rights reserved.
|
13
13
|
#
|
14
14
|
# Redistribution and use in source and binary forms, with or without
|
@@ -39,76 +39,47 @@
|
|
39
39
|
require 'recls/version'
|
40
40
|
|
41
41
|
require 'recls/api'
|
42
|
+
require 'recls/entry'
|
42
43
|
require 'recls/file_search'
|
43
44
|
require 'recls/foreach'
|
44
45
|
require 'recls/stat'
|
45
46
|
require 'recls/util'
|
46
47
|
require 'recls/ximpl/os'
|
47
48
|
|
49
|
+
|
50
|
+
# The *recls* module
|
51
|
+
#
|
52
|
+
# == Significant Components
|
53
|
+
# - Recls::Entry
|
54
|
+
# - Recls::absolute_path
|
55
|
+
# - Recls::absolute_path?
|
56
|
+
# - Recls::canonicalise_path
|
57
|
+
# - Recls::derive_relative_path
|
58
|
+
# - Recls::directory?
|
59
|
+
# - Recls::exist?
|
60
|
+
# - Recls::file?
|
61
|
+
# - Recls::file_rsearch
|
62
|
+
# - Recls::file_search
|
63
|
+
# - Recls::foreach
|
64
|
+
# - Recls::stat
|
65
|
+
module Recls
|
66
|
+
|
67
|
+
end # module Recls
|
68
|
+
|
48
69
|
module Recls
|
49
70
|
|
50
71
|
# Represents the "all" wildcards string for the ambient operating
|
51
72
|
# system
|
52
73
|
WILDCARDS_ALL = Recls::Ximpl::OS::WILDCARDS_ALL
|
53
74
|
|
75
|
+
# The string sequence used to separate names in paths, e.g. "/" on UNIX
|
54
76
|
PATH_NAME_SEPARATOR = Recls::Ximpl::OS::PATH_NAME_SEPARATOR
|
55
77
|
|
78
|
+
# The string sequence used to separate paths, e.g. ":" on UNIX
|
56
79
|
PATH_SEPARATOR = Recls::Ximpl::OS::PATH_SEPARATOR
|
57
|
-
end
|
58
|
-
|
59
|
-
# ######################################################################### #
|
60
|
-
# Obsolete symbols
|
61
|
-
|
62
|
-
if not defined? RECLS_NO_OBSOLETE
|
63
|
-
|
64
|
-
module Recls
|
65
|
-
|
66
|
-
def self.pathNameSeparator
|
67
|
-
PATH_NAME_SEPARATOR
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.pathSeparator
|
71
|
-
PATH_SEPARATOR
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.wildcardsAll
|
75
|
-
WILDCARDS_ALL
|
76
|
-
end
|
77
|
-
|
78
|
-
class FileSearch
|
79
|
-
|
80
|
-
alias_method :searchRoot, :search_root
|
81
|
-
alias_method :pattern, :patterns
|
82
|
-
end
|
83
|
-
|
84
|
-
class Entry
|
85
|
-
|
86
|
-
alias_method :uncDrive, :drive
|
87
|
-
alias_method :directoryPath, :directory_path
|
88
|
-
alias_method :directoryParts, :directory_parts
|
89
|
-
alias_method :file, :file_full_name
|
90
|
-
alias_method :shortFile, :file_short_name
|
91
|
-
alias_method :fileBaseName, :file_name_only
|
92
|
-
alias_method :fileName, :file_name_only
|
93
|
-
alias_method :fileExt, :file_extension
|
94
|
-
alias_method :searchDirectory, :search_directory
|
95
|
-
alias_method :searchRelativePath, :search_relative_path
|
96
|
-
|
97
|
-
alias_method :isDirectory, :directory?
|
98
|
-
alias_method :isFile, :file?
|
99
|
-
#alias_method :isLink, :link?
|
100
|
-
alias_method :isReadOnly, :readonly?
|
101
|
-
def isUNC
|
102
|
-
|
103
|
-
d = drive
|
104
|
-
|
105
|
-
d and d.size > 2
|
106
|
-
end
|
80
|
+
end # module Recls
|
107
81
|
|
108
|
-
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
82
|
+
require 'recls/obsolete'
|
112
83
|
|
113
84
|
# ############################## end of file ############################# #
|
114
85
|
|
data/lib/recls/stat.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# Purpose: Defines the Recls.stat() method for the recls.Ruby library.
|
5
5
|
#
|
6
6
|
# Created: 24th July 2012
|
7
|
-
# Updated:
|
7
|
+
# Updated: 14th March 2019
|
8
8
|
#
|
9
9
|
# Author: Matthew Wilson
|
10
10
|
#
|
@@ -39,10 +39,27 @@
|
|
39
39
|
require 'recls/entry'
|
40
40
|
require 'recls/flags'
|
41
41
|
|
42
|
+
=begin
|
43
|
+
=end
|
44
|
+
|
45
|
+
class Object; end # :nodoc:
|
46
|
+
|
42
47
|
module Recls
|
43
48
|
|
44
|
-
#
|
45
|
-
# directory
|
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
|
46
63
|
def self.directory?(path, *args)
|
47
64
|
|
48
65
|
fe = self.stat(path, *args)
|
@@ -55,8 +72,20 @@ module Recls
|
|
55
72
|
fe
|
56
73
|
end
|
57
74
|
|
58
|
-
#
|
59
|
-
# file
|
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
|
60
89
|
def self.file?(path, *args)
|
61
90
|
|
62
91
|
fe = self.stat(path, *args)
|
@@ -69,13 +98,31 @@ module Recls
|
|
69
98
|
fe
|
70
99
|
end
|
71
100
|
|
72
|
-
#
|
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
|
73
113
|
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
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
|
79
126
|
def self.stat(path, *args)
|
80
127
|
|
81
128
|
flags = 0
|
@@ -86,50 +133,46 @@ module Recls
|
|
86
133
|
|
87
134
|
case args.size
|
88
135
|
when 0
|
136
|
+
|
89
137
|
;
|
90
138
|
when 1
|
139
|
+
|
91
140
|
case args[0]
|
92
141
|
when ::Integer
|
142
|
+
|
93
143
|
flags = args[0]
|
94
144
|
when ::String
|
145
|
+
|
95
146
|
search_root = args[0]
|
96
147
|
else
|
148
|
+
|
97
149
|
message = "argument '#{args[0]}' (#{args[0].class}) not valid"
|
98
150
|
end
|
99
151
|
when 2
|
152
|
+
|
100
153
|
if false
|
101
154
|
elsif ::Integer === args[0] && ::String === args[1]
|
155
|
+
|
102
156
|
flags = args[0]
|
103
157
|
search_root = args[1]
|
104
158
|
elsif ::String === args[0] && ::Integer === args[1]
|
159
|
+
|
105
160
|
search_root = args[0]
|
106
161
|
flags = args[1]
|
107
162
|
else
|
163
|
+
|
108
164
|
message = "invalid combination of arguments"
|
109
165
|
end
|
110
166
|
else
|
167
|
+
|
111
168
|
message = "too many arguments"
|
112
169
|
end
|
113
170
|
|
114
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
|
115
172
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
rescue Errno::ENOENT => x
|
120
|
-
|
121
|
-
x = x # suppress warning
|
122
|
-
|
123
|
-
if 0 != (flags & Recls::DETAILS_LATER)
|
124
|
-
|
125
|
-
Recls::Entry.new(path, nil, search_root, flags)
|
126
|
-
else
|
127
|
-
|
128
|
-
nil
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
173
|
+
Recls::Ximpl.stat_prep(path, search_root, flags)
|
174
|
+
end
|
175
|
+
end # module Recls
|
133
176
|
|
134
177
|
# ############################## end of file ############################# #
|
135
178
|
|