recls-ruby 2.7.5 → 2.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/recls/util.rb +28 -4
- data/lib/recls/version.rb +4 -3
- data/lib/recls/ximpl/util.rb +114 -15
- data/test/unit/tc_recls_util.rb +157 -84
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd3873b6ab2b854777d003cfefd78240322da3ec
|
4
|
+
data.tar.gz: 35234197d743227278a98b4bb6d645f5c895a452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62d7e2ee09b3b4ed8f8908a4ecbc5fb4c82b3c0cc6c553310913384c4573bebca95a8dd6c960f57c7555511fc954541c6542ef11a5d328cd4abed411ccae2689
|
7
|
+
data.tar.gz: a7609496ada38d41d30b054603fbf28300961eae8f3b18012ab3ff68ac41d294b378a32c2d3093e50065bd1ee783b9287dac4f70cb5d5d709d7ad8ee0ebc3136
|
data/README.md
CHANGED
@@ -26,3 +26,9 @@ Defect reports, feature requests, and pull requests are welcome on https://githu
|
|
26
26
|
## License
|
27
27
|
|
28
28
|
**recls.Ruby** is released under the 3-clause BSD license. See LICENSE for details.
|
29
|
+
|
30
|
+
## Compatibility
|
31
|
+
|
32
|
+
From v2.8 onwards, recls.Ruby is compatible only with Ruby 2.0+
|
33
|
+
|
34
|
+
|
data/lib/recls/util.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Utility module functions for recls library
|
5
5
|
#
|
6
6
|
# Created: 17th February 2014
|
7
|
-
# Updated:
|
7
|
+
# Updated: 25th January 2018
|
8
8
|
#
|
9
9
|
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2012-
|
11
|
+
# Copyright (c) 2012-2018, 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
|
@@ -63,11 +63,35 @@ module Recls
|
|
63
63
|
|
64
64
|
# Combines paths, optionally canonicalising them
|
65
65
|
#
|
66
|
-
|
66
|
+
# === Signature
|
67
|
+
#
|
68
|
+
# * *Parameters:*
|
69
|
+
# - +paths+:: [ [ ::String, ::Recls::Entry ] ] Array of 1 or more path
|
70
|
+
# elements to be combined
|
71
|
+
# - +options+:: [::Hash] Options that moderate the combination
|
72
|
+
#
|
73
|
+
# * *Parameters:*
|
74
|
+
# - +:canonicalise+:: [boolean] Causes the evaluated path to be
|
75
|
+
# canonicalised - with +Recls.canonicalise_path+ - before it is
|
76
|
+
# returned
|
77
|
+
# - +:clean+:: [boolean] Causes the evaluated path to be cleaned
|
78
|
+
# (i.e. sent to +cleanpath+) before it is returned. Ignored if
|
79
|
+
# +:canonicalise+ is specified
|
80
|
+
# - +:clean_path+:: [boolean] Equivalent to +:clean+, but deprecated
|
81
|
+
# and may be removed in a future version
|
82
|
+
#
|
83
|
+
# === Return
|
84
|
+
# The combined path
|
85
|
+
def self.combine_paths(*paths, **options)
|
67
86
|
|
68
|
-
|
87
|
+
paths = paths.reject { |p| p.nil? }
|
88
|
+
|
89
|
+
raise ArgumentError, 'must specify one or more path elements' if paths.empty?
|
90
|
+
|
91
|
+
return Recls::Ximpl.combine_paths paths, options
|
69
92
|
end
|
70
93
|
end
|
71
94
|
|
72
95
|
# ############################## end of file ############################# #
|
73
96
|
|
97
|
+
|
data/lib/recls/version.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Version for recls library
|
5
5
|
#
|
6
6
|
# Created: 14th February 2014
|
7
|
-
# Updated:
|
7
|
+
# Updated: 5th February 2018
|
8
8
|
#
|
9
9
|
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2012-
|
11
|
+
# Copyright (c) 2012-2018, 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,7 +39,7 @@
|
|
39
39
|
module Recls
|
40
40
|
|
41
41
|
# Current version of the recls.Ruby library
|
42
|
-
VERSION = '2.
|
42
|
+
VERSION = '2.8.2'
|
43
43
|
|
44
44
|
private
|
45
45
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
@@ -51,3 +51,4 @@ end
|
|
51
51
|
|
52
52
|
# ############################## end of file ############################# #
|
53
53
|
|
54
|
+
|
data/lib/recls/ximpl/util.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Internal implementation constructs for the recls library.
|
5
5
|
#
|
6
6
|
# Created: 24th July 2012
|
7
|
-
# Updated:
|
7
|
+
# Updated: 25th January 2018
|
8
8
|
#
|
9
9
|
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
-
# Copyright (c) 2012-
|
11
|
+
# Copyright (c) 2012-2018, 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
|
@@ -52,6 +52,7 @@ module Recls
|
|
52
52
|
return true if ?/ == c
|
53
53
|
|
54
54
|
if Recls::Ximpl::OS::OS_IS_WINDOWS
|
55
|
+
|
55
56
|
return true if ?\\ == c
|
56
57
|
end
|
57
58
|
|
@@ -126,6 +127,7 @@ module Recls
|
|
126
127
|
#
|
127
128
|
# NOTE: this works for both rooted and unrooted paths
|
128
129
|
if p =~ /^([a-zA-Z]:)/
|
130
|
+
|
129
131
|
return [ $1, $' ]
|
130
132
|
end
|
131
133
|
|
@@ -133,18 +135,22 @@ module Recls
|
|
133
135
|
#
|
134
136
|
# NOTE: there are several permutations ...
|
135
137
|
if p =~ /^(\\\\[^\\\/:*?<>|]+\\[^\\\/:*?<>|]+)([\\\/].*)$/
|
138
|
+
|
136
139
|
# \\server\share{\{... rest of path}}
|
137
140
|
return [ $1, $2 ]
|
138
141
|
end
|
139
142
|
if p =~ /^(\\\\[^\\\/:*?<>|]+\\[^\\\/:*?<>|]+)$/
|
143
|
+
|
140
144
|
# \\server\share
|
141
145
|
return [ $1, nil ]
|
142
146
|
end
|
143
147
|
if p =~ /^(\\\\[^\\\/:*?<>|]+\\)$/
|
148
|
+
|
144
149
|
# \\server\
|
145
150
|
return [ $1, nil ]
|
146
151
|
end
|
147
152
|
if p =~ /^(\\\\[^\\\/:*?<>|]+)$/
|
153
|
+
|
148
154
|
# \\server
|
149
155
|
return [ $1, nil ]
|
150
156
|
end
|
@@ -167,10 +173,13 @@ module Recls
|
|
167
173
|
parts << wr if wr
|
168
174
|
|
169
175
|
until rem.nil? || rem.empty?
|
176
|
+
|
170
177
|
if rem =~ /^([^\\\/]*[\\\/])/
|
178
|
+
|
171
179
|
parts << $1
|
172
180
|
rem = $'
|
173
181
|
else
|
182
|
+
|
174
183
|
parts << rem
|
175
184
|
rem = ''
|
176
185
|
end
|
@@ -199,15 +208,19 @@ module Recls
|
|
199
208
|
remainder = nil if not remainder or remainder.empty?
|
200
209
|
|
201
210
|
if not remainder or remainder.empty?
|
211
|
+
|
202
212
|
f2_directory = nil
|
203
213
|
f3_basename = nil
|
204
214
|
f4_nameonly = nil
|
205
215
|
f5_extension = nil
|
206
216
|
else
|
217
|
+
|
207
218
|
if remainder =~ /^(.*[\\\/])([^\\\/]*)$/
|
219
|
+
|
208
220
|
f2_directory = $1
|
209
221
|
f3_basename = $2
|
210
222
|
else
|
223
|
+
|
211
224
|
f2_directory = nil
|
212
225
|
f3_basename = remainder
|
213
226
|
f4_nameonly = nil
|
@@ -218,18 +231,23 @@ module Recls
|
|
218
231
|
f3_basename = nil if not f3_basename or f3_basename.empty?
|
219
232
|
|
220
233
|
if f3_basename
|
234
|
+
|
221
235
|
# special case: treat '.' and '..' as file-name only
|
222
236
|
if '.' == f3_basename or '..' == f3_basename
|
237
|
+
|
223
238
|
f4_nameonly = f3_basename
|
224
239
|
f5_extension = nil
|
225
240
|
elsif f3_basename =~ /^(.*)(\.[^.]*)$/
|
241
|
+
|
226
242
|
f4_nameonly = $1
|
227
243
|
f5_extension = $2
|
228
244
|
else
|
245
|
+
|
229
246
|
f4_nameonly = f3_basename
|
230
247
|
f5_extension = nil
|
231
248
|
end
|
232
249
|
else
|
250
|
+
|
233
251
|
f4_nameonly = nil
|
234
252
|
f5_extension = nil
|
235
253
|
end
|
@@ -270,11 +288,14 @@ module Recls
|
|
270
288
|
next if part.empty?
|
271
289
|
|
272
290
|
if path_is_rooted.nil?
|
291
|
+
|
273
292
|
path_is_rooted = self.is_path_name_separator(part[0])
|
274
293
|
end
|
275
294
|
|
276
295
|
if ?. == part[0]
|
296
|
+
|
277
297
|
if self.is_path_name_separator(part[1])
|
298
|
+
|
278
299
|
# single dots, so ...
|
279
300
|
|
280
301
|
# ... remember the last instance, and ...
|
@@ -283,7 +304,9 @@ module Recls
|
|
283
304
|
# ... skip to leave this out of the result
|
284
305
|
next
|
285
306
|
elsif ?. == part[1]
|
307
|
+
|
286
308
|
if self.is_path_name_separator(part[2])
|
309
|
+
|
287
310
|
# double dots, so ...
|
288
311
|
# ... skip this and pop prior from the new list iff:
|
289
312
|
#
|
@@ -291,26 +314,34 @@ module Recls
|
|
291
314
|
# 2. the last element in the new list is not the root directory; AND
|
292
315
|
# 3. the last element in the list is not a dots directory
|
293
316
|
if not newParts.empty? # 1.
|
317
|
+
|
294
318
|
priorPart = newParts[-1]
|
295
319
|
if 1 == newParts.size and OS.is_root_dir_(priorPart)
|
320
|
+
|
296
321
|
# 2.
|
297
322
|
next
|
298
323
|
else
|
324
|
+
|
299
325
|
dirtype = OS.get_number_of_dots_dir_(priorPart)
|
300
326
|
if 0 == dirtype # 3.
|
327
|
+
|
301
328
|
if newParts.pop
|
329
|
+
|
302
330
|
next
|
303
331
|
end
|
304
332
|
end
|
305
333
|
end
|
306
334
|
end
|
307
335
|
else
|
336
|
+
|
308
337
|
# it's a ..X part
|
309
338
|
end
|
310
339
|
else
|
340
|
+
|
311
341
|
# it's a .X part
|
312
342
|
end
|
313
343
|
else
|
344
|
+
|
314
345
|
# it's a non-dots part
|
315
346
|
end
|
316
347
|
|
@@ -320,25 +351,35 @@ module Recls
|
|
320
351
|
consume_basename = false
|
321
352
|
|
322
353
|
if basename
|
354
|
+
|
323
355
|
if ?. == basename[0]
|
356
|
+
|
324
357
|
if 1 == basename.size
|
358
|
+
|
325
359
|
# single dots
|
326
360
|
if newParts.empty?
|
361
|
+
|
327
362
|
lastSingleDots = false
|
328
363
|
else
|
364
|
+
|
329
365
|
consume_basename = true
|
330
366
|
end
|
331
367
|
elsif ?. == basename[1] and 2 == basename.size
|
368
|
+
|
332
369
|
# double dots, so ...
|
333
370
|
#
|
334
371
|
# ... pop unless we already have some outstanding double dots
|
335
372
|
if newParts.empty?
|
373
|
+
|
336
374
|
newParts << '..'
|
337
375
|
consume_basename = true
|
338
376
|
elsif 1 == newParts.size && 1 == newParts[0].size && Util.is_path_name_separator(newParts[0][0])
|
377
|
+
|
339
378
|
consume_basename = true
|
340
379
|
else
|
380
|
+
|
341
381
|
if 2 != OS.get_number_of_dots_dir_(newParts[-1])
|
382
|
+
|
342
383
|
newParts.pop
|
343
384
|
consume_basename = true
|
344
385
|
end
|
@@ -352,23 +393,30 @@ module Recls
|
|
352
393
|
newParts << lastSingleDots if lastSingleDots and newParts.empty?
|
353
394
|
|
354
395
|
if not newParts.empty?
|
396
|
+
|
355
397
|
if 2 == OS.get_number_of_dots_dir_(newParts[-1])
|
398
|
+
|
356
399
|
# the last element is the double-dots directory, but
|
357
400
|
# need to determine whether to ensure/remote a
|
358
401
|
# trailing slash
|
359
402
|
if basename and not basename.empty?
|
403
|
+
|
360
404
|
if not consume_basename
|
405
|
+
|
361
406
|
# leave as is
|
362
407
|
else
|
408
|
+
|
363
409
|
#
|
364
410
|
newParts[-1] = '..'
|
365
411
|
end
|
366
412
|
end
|
367
413
|
end
|
368
414
|
else
|
415
|
+
|
369
416
|
# handle case where all (double)-dots have eliminated
|
370
417
|
# all regular directories
|
371
418
|
if not basename or basename.empty? or consume_basename
|
419
|
+
|
372
420
|
newParts << '.'
|
373
421
|
end
|
374
422
|
end
|
@@ -395,8 +443,10 @@ module Recls
|
|
395
443
|
dummy3 = dummy3
|
396
444
|
|
397
445
|
if not f2_directory
|
446
|
+
|
398
447
|
canonicalised_directory = nil
|
399
448
|
else
|
449
|
+
|
400
450
|
canonicalised_directory, consume_basename = Util.canonicalise_parts(directory_parts, f3_basename)
|
401
451
|
f3_basename = nil if consume_basename
|
402
452
|
end
|
@@ -414,6 +464,7 @@ module Recls
|
|
414
464
|
when ::Recls::Entry
|
415
465
|
path = path.to_s
|
416
466
|
else
|
467
|
+
|
417
468
|
raise TypeError, "parameter path ('#{path}') is of type #{path.class} must be an instance of #{::String} or #{::Recls::Entry}"
|
418
469
|
end
|
419
470
|
|
@@ -430,6 +481,7 @@ module Recls
|
|
430
481
|
dummy6 = dummy6
|
431
482
|
|
432
483
|
if f2_directory =~ /^[\\\/]/
|
484
|
+
|
433
485
|
return path
|
434
486
|
end
|
435
487
|
|
@@ -438,8 +490,10 @@ module Recls
|
|
438
490
|
trailing_slash = Util.get_trailing_slash(path)
|
439
491
|
|
440
492
|
if '.' == path
|
493
|
+
|
441
494
|
return Util.trim_trailing_slash cwd
|
442
495
|
elsif 2 == path.size and trailing_slash
|
496
|
+
|
443
497
|
return Util.append_trailing_slash(cwd, path[1..1])
|
444
498
|
end
|
445
499
|
|
@@ -450,8 +504,10 @@ module Recls
|
|
450
504
|
path = canonicalise_path path
|
451
505
|
|
452
506
|
if trailing_slash
|
507
|
+
|
453
508
|
path = Util.append_trailing_slash path, trailing_slash
|
454
509
|
else
|
510
|
+
|
455
511
|
path = Util.trim_trailing_slash path
|
456
512
|
end
|
457
513
|
|
@@ -475,25 +531,31 @@ module Recls
|
|
475
531
|
# detecting the last (back)slash
|
476
532
|
|
477
533
|
if Recls::Ximpl::OS::OS_IS_WINDOWS
|
534
|
+
|
478
535
|
wr, rem = Util.get_windows_root(path)
|
479
536
|
|
480
537
|
# suppress unused warning
|
481
538
|
wr = wr
|
482
539
|
|
483
540
|
if not rem
|
541
|
+
|
484
542
|
return ''
|
485
543
|
else
|
544
|
+
|
486
545
|
path = rem
|
487
546
|
end
|
488
547
|
end
|
489
548
|
|
490
549
|
if not path.is_a? String
|
550
|
+
|
491
551
|
path = path.to_s
|
492
552
|
end
|
493
553
|
|
494
554
|
if path =~ /^.*[\/\\](.*)/
|
555
|
+
|
495
556
|
$1
|
496
557
|
else
|
558
|
+
|
497
559
|
path
|
498
560
|
end
|
499
561
|
end
|
@@ -510,21 +572,28 @@ module Recls
|
|
510
572
|
use_split_path = false
|
511
573
|
|
512
574
|
if Recls::Ximpl::OS::OS_IS_WINDOWS
|
575
|
+
|
513
576
|
if path.include? ?\\
|
577
|
+
|
514
578
|
use_split_path = true
|
515
579
|
end
|
516
580
|
end
|
517
581
|
|
518
582
|
if path.include? ?/
|
583
|
+
|
519
584
|
use_split_path = true
|
520
585
|
end
|
521
586
|
|
522
587
|
if use_split_path
|
588
|
+
|
523
589
|
ext = Util.split_path(path)[4]
|
524
590
|
else
|
591
|
+
|
525
592
|
if path =~ /^.*(\.[^.]*)$/
|
593
|
+
|
526
594
|
ext = $1
|
527
595
|
else
|
596
|
+
|
528
597
|
ext = nil
|
529
598
|
end
|
530
599
|
end
|
@@ -552,10 +621,13 @@ module Recls
|
|
552
621
|
directory_parts = []
|
553
622
|
|
554
623
|
until directory.empty?
|
624
|
+
|
555
625
|
if directory =~ /^([^\\\/]*[\\\/])/
|
626
|
+
|
556
627
|
directory_parts << $1
|
557
628
|
directory = $'
|
558
629
|
else
|
630
|
+
|
559
631
|
directory_parts << directory
|
560
632
|
directory = ''
|
561
633
|
end
|
@@ -581,6 +653,7 @@ module Recls
|
|
581
653
|
|
582
654
|
# if different windows root, then cannot provide relative
|
583
655
|
if path_splits[0] and origin_splits[0]
|
656
|
+
|
584
657
|
return path if path_splits[0] != origin_splits[0]
|
585
658
|
end
|
586
659
|
|
@@ -598,14 +671,17 @@ module Recls
|
|
598
671
|
origin_part = origin_parts[0]
|
599
672
|
|
600
673
|
if 1 == path_parts.size || 1 == origin_parts.size
|
674
|
+
|
601
675
|
path_part = Util.append_trailing_slash(path_part)
|
602
676
|
origin_part = Util.append_trailing_slash(origin_part)
|
603
677
|
end
|
604
678
|
|
605
679
|
if path_part == origin_part
|
680
|
+
|
606
681
|
path_parts.shift
|
607
682
|
origin_parts.shift
|
608
683
|
else
|
684
|
+
|
609
685
|
break
|
610
686
|
end
|
611
687
|
end
|
@@ -620,25 +696,46 @@ module Recls
|
|
620
696
|
end
|
621
697
|
|
622
698
|
|
623
|
-
def self.combine_paths(
|
699
|
+
def self.combine_paths(paths, options)
|
624
700
|
|
625
|
-
|
701
|
+
paths = [ paths ] unless ::Array === paths
|
702
|
+
abs_ix = 0
|
626
703
|
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
704
|
+
paths.each_with_index do |path, index|
|
705
|
+
|
706
|
+
dummy1, f2_directory, dummy2, dummy3, dummy4, dummy5, dummy6 = Util.split_path(path)
|
707
|
+
|
708
|
+
# suppress unused warnings
|
709
|
+
dummy1 = dummy1
|
710
|
+
dummy2 = dummy2
|
711
|
+
dummy3 = dummy3
|
712
|
+
dummy4 = dummy4
|
713
|
+
dummy5 = dummy5
|
714
|
+
dummy6 = dummy6
|
634
715
|
|
635
|
-
|
716
|
+
if f2_directory && Util.is_path_name_separator(f2_directory[0])
|
636
717
|
|
637
|
-
|
718
|
+
abs_ix = index
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
paths = paths[abs_ix..-1]
|
723
|
+
|
724
|
+
r = File.join *paths
|
725
|
+
|
726
|
+
cap = options[:canonicalise] || options[:canonicalize]
|
727
|
+
|
728
|
+
if cap
|
638
729
|
|
639
|
-
|
730
|
+
r = Recls.canonicalise_path r
|
731
|
+
else
|
732
|
+
|
733
|
+
clp = options[:clean] || options[:clean_path]
|
734
|
+
|
735
|
+
if clp
|
640
736
|
|
641
|
-
|
737
|
+
r = Pathname.new(r).cleanpath.to_s
|
738
|
+
end
|
642
739
|
end
|
643
740
|
|
644
741
|
r
|
@@ -665,6 +762,7 @@ module Recls
|
|
665
762
|
$stderr.puts "exception (#{x.class}): #{x}" if $DEBUG
|
666
763
|
|
667
764
|
if(0 != (STOP_ON_ACCESS_FAILURE & flags))
|
765
|
+
|
668
766
|
raise
|
669
767
|
end
|
670
768
|
|
@@ -676,3 +774,4 @@ end
|
|
676
774
|
|
677
775
|
# ############################## end of file ############################# #
|
678
776
|
|
777
|
+
|
data/test/unit/tc_recls_util.rb
CHANGED
@@ -9,150 +9,223 @@ require 'recls/util'
|
|
9
9
|
|
10
10
|
require 'test/unit'
|
11
11
|
|
12
|
+
class Test_combine_paths < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_nil_nil
|
15
|
+
|
16
|
+
assert_raise(::ArgumentError) { Recls.combine_paths(nil, nil) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_origin_nil
|
20
|
+
|
21
|
+
strings = [
|
22
|
+
|
23
|
+
'abc',
|
24
|
+
'abc/def',
|
25
|
+
'abc/def/ghi.ext',
|
26
|
+
]
|
27
|
+
|
28
|
+
strings.each do |s|
|
29
|
+
|
30
|
+
assert_equal s, Recls.combine_paths(nil, s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_path_nil
|
35
|
+
|
36
|
+
strings = [
|
37
|
+
|
38
|
+
'abc',
|
39
|
+
'abc/def',
|
40
|
+
'abc/def/ghi.ext',
|
41
|
+
]
|
42
|
+
|
43
|
+
strings.each do |s|
|
44
|
+
|
45
|
+
assert_equal s, Recls.combine_paths(s, nil)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_both_relative
|
50
|
+
|
51
|
+
assert_equal 'abc/def', Recls.combine_paths('abc', 'def')
|
52
|
+
assert_equal 'abc/def', Recls.combine_paths('abc/', 'def')
|
53
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc/def', 'ghi')
|
54
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc/def/', 'ghi')
|
55
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc', 'def/ghi')
|
56
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc/', 'def/ghi')
|
57
|
+
assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/.', 'def/ghi')
|
58
|
+
assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/./', 'def/ghi')
|
59
|
+
assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/.', 'def/ghi', clean_path: false)
|
60
|
+
assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/./', 'def/ghi', clean: false)
|
61
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc/.', 'def/ghi', clean_path: true)
|
62
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc/./', 'def/ghi', clean: true)
|
63
|
+
assert_equal 'abc/def/ghi', Recls.combine_paths('abc/./.', 'def/ghi', clean_path: true)
|
64
|
+
assert_equal 'abc/../def/ghi', Recls.combine_paths('abc/..', 'def/ghi')
|
65
|
+
assert_equal 'def/ghi', Recls.combine_paths('abc/..', 'def/ghi', clean_path: true)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_multiple_relative
|
69
|
+
|
70
|
+
assert_equal 'a/b/c/d/e/f/g', Recls.combine_paths('a', 'b', 'c', 'd/e/f/', 'g', clean: false)
|
71
|
+
assert_equal 'a/b/c/d/e/f/g', Recls.combine_paths('a', 'b', 'c', 'd/e/f/', 'g', clean: true)
|
72
|
+
|
73
|
+
assert_equal 'a/b/c/../d/e/f/g', Recls.combine_paths('a', 'b', 'c', '..', 'd/e/f/', 'g', clean: false)
|
74
|
+
assert_equal 'a/b/d/e/f/g', Recls.combine_paths('a', 'b', 'c', '..', 'd/e/f/', 'g/', clean: true)
|
75
|
+
assert_equal 'a/b/d/e/f/g/', Recls.combine_paths('a', 'b', 'c', '..', 'd/e/f/', 'g/', canonicalise: true)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_various_absolute_placings
|
79
|
+
|
80
|
+
assert_equal '/a/b/c/d/e/f/g', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', 'f/g')
|
81
|
+
|
82
|
+
assert_equal '/b/c/d/e/f/g', Recls.combine_paths('/', 'a', '/b', 'c', 'd/e', 'f/g')
|
83
|
+
|
84
|
+
assert_equal '/c/d/e/f/g', Recls.combine_paths('/', 'a', 'b', '/c', 'd/e', 'f/g')
|
85
|
+
|
86
|
+
assert_equal '/d/e/f/g', Recls.combine_paths('/', 'a', 'b', 'c', '/d/e', 'f/g')
|
87
|
+
|
88
|
+
assert_equal '/f/g', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g')
|
89
|
+
assert_equal '/f/g/', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g/')
|
90
|
+
assert_equal '/f/g', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g/', clean: true)
|
91
|
+
assert_equal '/f/g/', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g/', canonicalise: true)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
12
95
|
class Test_canonicalise_path < Test::Unit::TestCase
|
13
96
|
|
14
97
|
def test_nil
|
15
98
|
|
16
|
-
assert_nil(Recls
|
17
|
-
|
99
|
+
assert_nil(Recls.canonicalise_path(nil))
|
18
100
|
end
|
19
101
|
|
20
102
|
def test_empty
|
21
103
|
|
22
|
-
assert_equal('', Recls
|
23
|
-
|
104
|
+
assert_equal('', Recls.canonicalise_path(''))
|
24
105
|
end
|
25
106
|
|
26
107
|
def test_dots_directories
|
27
108
|
|
28
|
-
assert_equal('.', Recls
|
29
|
-
assert_equal('./', Recls
|
30
|
-
assert_equal('.', Recls
|
31
|
-
assert_equal('./', Recls
|
32
|
-
|
33
|
-
assert_equal('..', Recls::canonicalise_path('..'))
|
34
|
-
assert_equal('../', Recls::canonicalise_path('../'))
|
35
|
-
assert_equal('..', Recls::canonicalise_path('../.'))
|
36
|
-
assert_equal('../', Recls::canonicalise_path('.././'))
|
109
|
+
assert_equal('.', Recls.canonicalise_path('.'))
|
110
|
+
assert_equal('./', Recls.canonicalise_path('./'))
|
111
|
+
assert_equal('.', Recls.canonicalise_path('././.'))
|
112
|
+
assert_equal('./', Recls.canonicalise_path('./././'))
|
37
113
|
|
114
|
+
assert_equal('..', Recls.canonicalise_path('..'))
|
115
|
+
assert_equal('../', Recls.canonicalise_path('../'))
|
116
|
+
assert_equal('..', Recls.canonicalise_path('../.'))
|
117
|
+
assert_equal('../', Recls.canonicalise_path('.././'))
|
38
118
|
end
|
39
119
|
|
40
120
|
def test_files_only
|
41
121
|
|
42
|
-
assert_equal('a', Recls
|
43
|
-
assert_equal('file', Recls
|
44
|
-
assert_equal('file.ext', Recls
|
45
|
-
|
122
|
+
assert_equal('a', Recls.canonicalise_path('a'))
|
123
|
+
assert_equal('file', Recls.canonicalise_path('file'))
|
124
|
+
assert_equal('file.ext', Recls.canonicalise_path('file.ext'))
|
46
125
|
end
|
47
126
|
|
48
127
|
def test_zero_parts
|
49
128
|
|
50
129
|
if Recls::Ximpl::OS::OS_IS_WINDOWS
|
51
130
|
|
52
|
-
assert_equal('H:', Recls
|
53
|
-
|
54
|
-
assert_equal('\\\\server', Recls::canonicalise_path('\\\\server'))
|
55
|
-
assert_equal('\\\\server\\', Recls::canonicalise_path('\\\\server\\'))
|
56
|
-
assert_equal('\\\\server\\share', Recls::canonicalise_path('\\\\server\\share'))
|
57
|
-
assert_equal('\\\\server\\share/', Recls::canonicalise_path('\\\\server\\share/'))
|
131
|
+
assert_equal('H:', Recls.canonicalise_path('H:'))
|
58
132
|
|
133
|
+
assert_equal('\\\\server', Recls.canonicalise_path('\\\\server'))
|
134
|
+
assert_equal('\\\\server\\', Recls.canonicalise_path('\\\\server\\'))
|
135
|
+
assert_equal('\\\\server\\share', Recls.canonicalise_path('\\\\server\\share'))
|
136
|
+
assert_equal('\\\\server\\share/', Recls.canonicalise_path('\\\\server\\share/'))
|
59
137
|
end
|
60
|
-
|
61
138
|
end
|
62
139
|
|
63
140
|
def test_canonicalised_directories_one_level
|
64
141
|
|
65
|
-
assert_equal('abc', Recls
|
66
|
-
assert_equal('abc/', Recls
|
67
|
-
assert_equal('/abc', Recls
|
68
|
-
assert_equal('/abc/', Recls
|
69
|
-
|
70
|
-
end # test_canonicalised_directories_one_level
|
142
|
+
assert_equal('abc', Recls.canonicalise_path('abc'))
|
143
|
+
assert_equal('abc/', Recls.canonicalise_path('abc/'))
|
144
|
+
assert_equal('/abc', Recls.canonicalise_path('/abc'))
|
145
|
+
assert_equal('/abc/', Recls.canonicalise_path('/abc/'))
|
146
|
+
end
|
71
147
|
|
72
148
|
def test_canonicalised_directories_two_levels
|
73
149
|
|
74
|
-
assert_equal('abc/def', Recls
|
75
|
-
assert_equal('abc/def/', Recls
|
76
|
-
assert_equal('/abc/def', Recls
|
77
|
-
assert_equal('/abc/def/', Recls
|
78
|
-
|
79
|
-
end # test_canonicalised_directories_two_levels
|
150
|
+
assert_equal('abc/def', Recls.canonicalise_path('abc/def'))
|
151
|
+
assert_equal('abc/def/', Recls.canonicalise_path('abc/def/'))
|
152
|
+
assert_equal('/abc/def', Recls.canonicalise_path('/abc/def'))
|
153
|
+
assert_equal('/abc/def/', Recls.canonicalise_path('/abc/def/'))
|
154
|
+
end
|
80
155
|
|
81
156
|
def test_uncanonicalised_directories_one_level
|
82
157
|
|
83
|
-
assert_equal('.', Recls
|
84
|
-
assert_equal('./', Recls
|
85
|
-
assert_equal('/', Recls
|
86
|
-
assert_equal('/', Recls
|
87
|
-
|
88
|
-
assert_equal('..', Recls::canonicalise_path('..'))
|
89
|
-
assert_equal('../', Recls::canonicalise_path('../'))
|
90
|
-
assert_equal('/', Recls::canonicalise_path('/..'))
|
91
|
-
assert_equal('/', Recls::canonicalise_path('/../'))
|
158
|
+
assert_equal('.', Recls.canonicalise_path('.'))
|
159
|
+
assert_equal('./', Recls.canonicalise_path('./'))
|
160
|
+
assert_equal('/', Recls.canonicalise_path('/.'))
|
161
|
+
assert_equal('/', Recls.canonicalise_path('/./'))
|
92
162
|
|
93
|
-
|
163
|
+
assert_equal('..', Recls.canonicalise_path('..'))
|
164
|
+
assert_equal('../', Recls.canonicalise_path('../'))
|
165
|
+
assert_equal('/', Recls.canonicalise_path('/..'))
|
166
|
+
assert_equal('/', Recls.canonicalise_path('/../'))
|
167
|
+
end
|
94
168
|
|
95
169
|
def test_single_canonicalisation
|
96
170
|
|
97
|
-
assert_equal('dir.1/', Recls
|
98
|
-
assert_equal('dir.1/', Recls
|
99
|
-
assert_equal('dir.1/', Recls
|
100
|
-
assert_equal('dir.1/', Recls
|
101
|
-
|
171
|
+
assert_equal('dir.1/', Recls.canonicalise_path('dir.1/'))
|
172
|
+
assert_equal('dir.1/', Recls.canonicalise_path('dir.1/./'))
|
173
|
+
assert_equal('dir.1/', Recls.canonicalise_path('./dir.1/./'))
|
174
|
+
assert_equal('dir.1/', Recls.canonicalise_path('./dir.1/.'))
|
102
175
|
end
|
103
176
|
|
104
177
|
def test_double_canonicalisation
|
105
178
|
|
106
|
-
assert_equal('dir.1/dir.2/', Recls
|
107
|
-
assert_equal('dir.1/dir.2/', Recls
|
108
|
-
assert_equal('dir.1/dir.2/', Recls
|
109
|
-
assert_equal('dir.1/dir.2/', Recls
|
110
|
-
assert_equal('dir.1/dir.2/', Recls
|
179
|
+
assert_equal('dir.1/dir.2/', Recls.canonicalise_path('dir.1/dir.2/'))
|
180
|
+
assert_equal('dir.1/dir.2/', Recls.canonicalise_path('dir.1/dir.2/dir.3/../'))
|
181
|
+
assert_equal('dir.1/dir.2/', Recls.canonicalise_path('dir.1/dir.2/dir.3/../'))
|
182
|
+
assert_equal('dir.1/dir.2/', Recls.canonicalise_path('dir.1/dir.3/../dir.2/'))
|
183
|
+
assert_equal('dir.1/dir.2/', Recls.canonicalise_path('dir.3/../dir.1/dir.2/'))
|
111
184
|
|
112
|
-
assert_equal('../dir.1/dir.2/', Recls
|
113
|
-
assert_equal('../dir.4/', Recls
|
185
|
+
assert_equal('../dir.1/dir.2/', Recls.canonicalise_path('../dir.1/dir.2/'))
|
186
|
+
assert_equal('../dir.4/', Recls.canonicalise_path('../dir.1/../dir.4/'))
|
114
187
|
|
115
|
-
assert_equal('/dir.1/dir.2/', Recls
|
116
|
-
assert_equal('/dir.1/dir.2/', Recls
|
117
|
-
assert_equal('/dir.1/dir.2/', Recls
|
118
|
-
assert_equal('/dir.1/dir.2/', Recls
|
119
|
-
assert_equal('/dir.1/dir.2/', Recls
|
188
|
+
assert_equal('/dir.1/dir.2/', Recls.canonicalise_path('/dir.1/dir.2/'))
|
189
|
+
assert_equal('/dir.1/dir.2/', Recls.canonicalise_path('/dir.1/dir.2/dir.3/../'))
|
190
|
+
assert_equal('/dir.1/dir.2/', Recls.canonicalise_path('/dir.1/dir.2/dir.3/../'))
|
191
|
+
assert_equal('/dir.1/dir.2/', Recls.canonicalise_path('/dir.1/dir.3/../dir.2/'))
|
192
|
+
assert_equal('/dir.1/dir.2/', Recls.canonicalise_path('/dir.3/../dir.1/dir.2/'))
|
120
193
|
|
121
|
-
assert_equal('/dir.1/dir.2/', Recls
|
122
|
-
assert_equal('/dir.4/', Recls
|
194
|
+
assert_equal('/dir.1/dir.2/', Recls.canonicalise_path('/../dir.1/dir.2/'))
|
195
|
+
assert_equal('/dir.4/', Recls.canonicalise_path('/../dir.1/../dir.4/'))
|
123
196
|
|
124
|
-
assert_equal('/dir.14/', Recls
|
125
|
-
assert_equal('/', Recls
|
126
|
-
assert_equal('/', Recls
|
127
|
-
assert_equal('dir.14/', Recls
|
128
|
-
assert_equal('.', Recls
|
129
|
-
assert_equal('..', Recls
|
197
|
+
assert_equal('/dir.14/', Recls.canonicalise_path('/dir.14/dir.2/..'))
|
198
|
+
assert_equal('/', Recls.canonicalise_path('/dir.14/dir.2/../..'))
|
199
|
+
assert_equal('/', Recls.canonicalise_path('/dir.14/dir.2/../../..'))
|
200
|
+
assert_equal('dir.14/', Recls.canonicalise_path('dir.14/dir.2/..'))
|
201
|
+
assert_equal('.', Recls.canonicalise_path('dir.14/dir.2/../..'))
|
202
|
+
assert_equal('..', Recls.canonicalise_path('dir.14/dir.2/../../..'))
|
130
203
|
|
131
204
|
if Recls::Ximpl::OS::OS_IS_WINDOWS
|
132
205
|
|
133
|
-
assert_equal('H:\\dir.1\\dir.2\\', Recls
|
134
|
-
assert_equal('H:\\dir.1\\dir.2\\', Recls
|
135
|
-
assert_equal('H:\\dir.1\\dir.2\\', Recls
|
136
|
-
assert_equal('H:\\dir.1\\dir.2\\', Recls
|
137
|
-
assert_equal('H:\\dir.1\\dir.2\\', Recls
|
138
|
-
|
139
|
-
assert_equal('H:\\dir.43\\dir.5\\', Recls::canonicalise_path('H:\\..\\dir.43\\dir.5\\'))
|
140
|
-
assert_equal('H:\\dir.42\\', Recls::canonicalise_path('H:\\..\\dir.1\\..\\dir.42\\'))
|
206
|
+
assert_equal('H:\\dir.1\\dir.2\\', Recls.canonicalise_path('H:\\dir.1\\dir.2\\'))
|
207
|
+
assert_equal('H:\\dir.1\\dir.2\\', Recls.canonicalise_path('H:\\dir.1\\dir.2\\dir.3\\..\\'))
|
208
|
+
assert_equal('H:\\dir.1\\dir.2\\', Recls.canonicalise_path('H:\\dir.1\\dir.2\\dir.3\\..\\'))
|
209
|
+
assert_equal('H:\\dir.1\\dir.2\\', Recls.canonicalise_path('H:\\dir.1\\dir.3\\..\\dir.2\\'))
|
210
|
+
assert_equal('H:\\dir.1\\dir.2\\', Recls.canonicalise_path('H:\\dir.3\\..\\dir.1\\dir.2\\'))
|
141
211
|
|
212
|
+
assert_equal('H:\\dir.43\\dir.5\\', Recls.canonicalise_path('H:\\..\\dir.43\\dir.5\\'))
|
213
|
+
assert_equal('H:\\dir.42\\', Recls.canonicalise_path('H:\\..\\dir.1\\..\\dir.42\\'))
|
142
214
|
end
|
143
|
-
|
144
215
|
end
|
145
216
|
|
146
217
|
def test_complex_examples
|
147
218
|
|
148
|
-
assert_equal('../dir.11/dir.22/dir.33/file3.', Recls
|
149
|
-
assert_equal('/dir.11/dir.22/dir.33/file3.', Recls
|
150
|
-
assert_equal('../dir.11/dir.22/dir.33/file3.', Recls
|
219
|
+
assert_equal('../dir.11/dir.22/dir.33/file3.', Recls.canonicalise_path('abc/.././././.././dir.1/../dir.11/dir.22/dir.33/file3.'))
|
220
|
+
assert_equal('/dir.11/dir.22/dir.33/file3.', Recls.canonicalise_path('/abc/.././././.././dir.1/../dir.11/dir.22/dir.33/file3.'))
|
221
|
+
assert_equal('../dir.11/dir.22/dir.33/file3.', Recls.canonicalise_path('./././abc/.././././.././dir.1/../dir.11/dir.22/././dir.33/././file3.'))
|
151
222
|
|
152
223
|
if Recls::Ximpl::OS::OS_IS_WINDOWS
|
153
224
|
|
154
225
|
end
|
155
|
-
|
156
226
|
end
|
157
227
|
end
|
158
228
|
|
229
|
+
# ############################## end of file ############################# #
|
230
|
+
|
231
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recls-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
RECursive LS for Ruby
|