recls-ruby 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 518087f6042cc31fe5d05f724d0f16e00d7192fa
4
+ data.tar.gz: e480c2ce6cf0aab32dc5ab01a1797c6c5fa275c4
5
+ SHA512:
6
+ metadata.gz: 20fd43b0fff86081eb62e1ea43d889c45bfe0c9add816b70e9d62a568ba2203af551cdaeecbb221bb2d15939a1e31d072f3c4d8f0a4c9a0c86c8cac5bba1ad76
7
+ data.tar.gz: baa78f624be64f88e3ca5bbc2ec689ac23c7d907bd4ac1dba793816c3d978f70d30891089bf99661c689284093dfde6842640aac5211a1578646573d7baf597e
data/LICENSE ADDED
@@ -0,0 +1,31 @@
1
+ recls.Ruby
2
+
3
+ Copyright (c) 2003-2016, Matthew Wilson and Synesis Software
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the names of recls or recls.Ruby nor the names of the copyright
17
+ holder nor the names of its contributors may be used to endorse or promote
18
+ products derived from this software without specific prior written
19
+ permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # recls.Ruby
2
+ recls for Ruby
@@ -0,0 +1,15 @@
1
+
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'recls'
5
+
6
+ # To find only hidden files, need to:
7
+ #
8
+ # 1. Ensure that they are returned in search, by including Recls::SHOW_HIDDEN
9
+ # 2. Filter returned entries by hidden? attribute
10
+ Recls::FileSearch.new('.', Recls::WILDCARDS_ALL, Recls::FILES | Recls::RECURSIVE | Recls::SHOW_HIDDEN).each do |fe|
11
+
12
+ puts fe.path if fe.hidden?
13
+
14
+ end
15
+
@@ -0,0 +1,14 @@
1
+
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'recls'
5
+
6
+ # To find only readonly files, need to:
7
+ #
8
+ # 1. Filter returned entries by readonly? attribute
9
+ Recls::FileSearch.new('.', Recls::WILDCARDS_ALL, Recls::FILES | Recls::RECURSIVE).each do |fe|
10
+
11
+ puts fe.path if fe.readonly?
12
+
13
+ end
14
+
data/lib/recls.rb ADDED
@@ -0,0 +1,41 @@
1
+ # ######################################################################### #
2
+ # File: recls.rb
3
+ #
4
+ # Purpose: Top-level include for recls.Ruby library
5
+ #
6
+ # Created: 13th January 2012
7
+ # Updated: 27th August 2015
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2012-2015, 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
+ require 'recls/recls'
40
+
41
+ # ############################## end of file ############################# #
@@ -0,0 +1,328 @@
1
+ # ######################################################################### #
2
+ # File: recls/entry.rb
3
+ #
4
+ # Purpose: Defines the Recls::Entry class for the recls.Ruby library.
5
+ #
6
+ # Created: 24th July 2012
7
+ # Updated: 28th December 2015
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2012-2015, 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
+ require 'recls/ximpl/os'
40
+ require 'recls/ximpl/' + (Recls::Ximpl::OS::OS_IS_WINDOWS ? 'windows' : 'unix')
41
+ require 'recls/ximpl/util'
42
+ require 'recls/flags'
43
+
44
+ module Recls
45
+
46
+ class Entry
47
+
48
+ private
49
+ def self.get_compare_path_(path)
50
+ return path.upcase if Recls::Ximpl::OS::OS_IS_WINDOWS
51
+ path
52
+ end
53
+ public
54
+
55
+ # initialises an entry instance from the given path,
56
+ # file_stat, and search_dir
57
+ def initialize(path, file_stat, search_dir, flags)
58
+
59
+ @file_stat = file_stat
60
+
61
+ @path = Recls::Ximpl.absolute_path path
62
+ @short_path = nil
63
+ @compare_path = Entry.get_compare_path_ @path
64
+ @hash = @compare_path.hash
65
+
66
+ windows_drive, directory, basename, file_name, file_ext = Recls::Ximpl::Util.split_path @path
67
+
68
+ @drive = windows_drive
69
+ @directory_path = "#{windows_drive}#{directory}"
70
+ @directory = directory ? directory : ''
71
+ @directory_parts = Recls::Ximpl.directory_parts_from_directory directory
72
+ @file_full_name = basename ? basename : ''
73
+ @file_short_name = nil
74
+ @file_name_only = file_name ? file_name : ''
75
+ @file_extension = file_ext ? file_ext : ''
76
+
77
+ @search_directory = search_dir
78
+ @search_relative_path = Recls::Ximpl.derive_relative_path search_dir, @path
79
+ @search_relative_directory_path = Recls::Ximpl.derive_relative_path search_dir, @directory_path
80
+ @search_relative_directory = @search_relative_directory_path
81
+ @search_relative_directory_parts = Recls::Ximpl.directory_parts_from_directory @search_relative_directory
82
+
83
+ if 0 != (Recls::MARK_DIRECTORIES & flags) && directory?
84
+ @path = Recls::Ximpl::Util.append_trailing_slash @path
85
+ @search_relative_path = Recls::Ximpl::Util.append_trailing_slash @search_relative_path
86
+ end
87
+
88
+ @dev = @file_stat.dev if @file_stat
89
+ @ino = @file_stat.ino if @file_stat
90
+ @nlink = @file_stat.nlink if @file_stat
91
+
92
+ if Recls::Ximpl::OS::OS_IS_WINDOWS && @file_stat
93
+ @dev = @file_stat.by_handle_information.volume_id
94
+ @ino = @file_stat.by_handle_information.file_index
95
+ @nlink = @file_stat.by_handle_information.num_links
96
+ @short_path = @file_stat.short_path
97
+ @file_short_name = Recls::Ximpl::Util.split_path(@short_path)[2]
98
+ else
99
+ end
100
+ end
101
+
102
+ # ##########################
103
+ # Name-related attributes
104
+
105
+ attr_reader :compare_path
106
+
107
+ attr_reader :path
108
+ attr_reader :short_path
109
+ attr_reader :drive
110
+ attr_reader :directory_path
111
+ alias_method :dirname, :directory_path
112
+ attr_reader :directory
113
+ attr_reader :directory_parts
114
+ attr_reader :file_full_name
115
+ attr_reader :file_short_name
116
+ alias_method :basename, :file_full_name
117
+ attr_reader :file_name_only
118
+ alias_method :stem, :file_name_only
119
+ attr_reader :file_extension
120
+ alias_method :extension, :file_extension
121
+ attr_reader :search_directory
122
+ attr_reader :search_relative_path
123
+ attr_reader :search_relative_directory
124
+ attr_reader :search_relative_directory_path
125
+ attr_reader :search_relative_directory_parts
126
+
127
+ # ##########################
128
+ # Nature attributes
129
+
130
+ # indicates whether the given entry existed at the time the entry
131
+ # instance was created
132
+ def exist?
133
+
134
+ not @file_stat.nil?
135
+ end
136
+
137
+ # indicates whether the given entry is hidden
138
+ def hidden?
139
+
140
+ @file_stat.hidden?
141
+ end
142
+
143
+ # indicates whether the given entry is readonly
144
+ def readonly?
145
+
146
+ not @file_stat.writable?
147
+ end
148
+
149
+ # ##########################
150
+ # Comparison
151
+
152
+ if Recls::Ximpl::OS::OS_IS_WINDOWS
153
+
154
+ def system?
155
+
156
+ @file_stat.system?
157
+ end
158
+
159
+ def archive?
160
+
161
+ @file_stat.archive?
162
+ end
163
+
164
+ def device?
165
+
166
+ @file_stat.device?
167
+ end
168
+
169
+ def normal?
170
+
171
+ @file_stat.normal?
172
+ end
173
+
174
+ def temporary?
175
+
176
+ @file_stat.temporary?
177
+ end
178
+
179
+ def compressed?
180
+
181
+ @file_stat.compressed?
182
+ end
183
+
184
+ def encrypted?
185
+
186
+ @file_stat.encrypted?
187
+ end
188
+ end
189
+
190
+ # indicates whether the given entry represents a directory
191
+ def directory?
192
+
193
+ @file_stat.directory?
194
+ end
195
+
196
+ # indicates whether the given entry represents a file
197
+ def file?
198
+
199
+ @file_stat.file?
200
+ end
201
+
202
+ # indicates whether the given entry represents a link
203
+ def link?
204
+
205
+ @file_stat.link?
206
+ end
207
+
208
+ # indicates whether the given entry represents a socket
209
+ def socket?
210
+
211
+ @file_stat.socket?
212
+ end
213
+
214
+ # ##########################
215
+ # Size attributes
216
+
217
+ # indicates the size of the given entry
218
+ def size
219
+
220
+ @file_stat.size
221
+ end
222
+
223
+ # ##########################
224
+ # File-system entry attributes
225
+
226
+ # indicates the device of the given entry
227
+ #
228
+ # On Windows, this will be 0 if the entry cannot be
229
+ # opened
230
+ def dev
231
+
232
+ @dev
233
+ end
234
+
235
+ # indicates the ino of the given entry
236
+ #
237
+ # On Windows, this will be 0 if the entry cannot be
238
+ # opened
239
+ def ino
240
+
241
+ @ino
242
+ end
243
+
244
+ # number of links to the given entry
245
+ #
246
+ # On Windows, this will be 0 if the entry cannot be
247
+ # opened
248
+ def nlink
249
+
250
+ @nlink
251
+ end
252
+
253
+ # ##########################
254
+ # Time attributes
255
+
256
+ # indicates the last access time of the entry
257
+ def last_access_time
258
+
259
+ @file_stat.atime
260
+ end
261
+
262
+ # indicates the modification time of the entry
263
+ def modification_time
264
+
265
+ @file_stat.mtime
266
+ end
267
+
268
+ # ##########################
269
+ # Comparison
270
+
271
+ # determines whether rhs is an instance of Entry and
272
+ # refers to the same path
273
+ def eql?(rhs)
274
+
275
+ case rhs
276
+ when self.class
277
+ return compare_path == rhs.compare_path
278
+ else
279
+ return false
280
+ end
281
+ end
282
+
283
+ # determines whether rhs refers to the same path
284
+ def ==(rhs)
285
+
286
+ case rhs
287
+ when String
288
+ return compare_path == Entry.get_compare_path_(rhs)
289
+ when self.class
290
+ return compare_path == rhs.compare_path
291
+ else
292
+ return false
293
+ end
294
+ end
295
+
296
+ # compares this instance with rhs
297
+ def <=>(rhs)
298
+
299
+ compare_path <=> rhs.compare_path
300
+ end
301
+
302
+ # the hash
303
+ def hash
304
+
305
+ @hash
306
+ end
307
+
308
+ # ##########################
309
+ # Conversion
310
+
311
+ # represents the entry as a string (in the form of
312
+ # the full path)
313
+ def to_s
314
+
315
+ path
316
+ end
317
+
318
+ # represents the entry as a string (in the form of
319
+ # the full path)
320
+ def to_str
321
+
322
+ path
323
+ end
324
+ end
325
+ end
326
+
327
+ # ############################## end of file ############################# #
328
+