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.
@@ -4,7 +4,7 @@
4
4
  # Purpose: Utility module functions for recls library
5
5
  #
6
6
  # Created: 17th February 2014
7
- # Updated: 21st March 2019
7
+ # Updated: 14th April 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
@@ -36,33 +36,64 @@
36
36
  # ######################################################################### #
37
37
 
38
38
 
39
+ require 'recls/stat'
39
40
  require 'recls/ximpl/util'
40
41
  require 'recls/ximpl/os'
41
42
 
43
+ =begin
44
+ =end
45
+
46
+ class Object; end # :nodoc:
47
+
42
48
  module Recls
43
49
 
44
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
45
59
  def self.absolute_path(path)
46
60
 
47
61
  return path.path if 'Recls::Entry' === path.class.to_s
48
62
 
49
- return Recls::Ximpl.absolute_path path
63
+ Recls::Ximpl.absolute_path path
50
64
  end
51
65
 
52
66
  # Canonicalises the given path, by removing dots ('.' and '..')
53
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
54
76
  def self.canonicalise_path(path)
55
77
 
56
78
  path = path.path if 'Recls::Entry' === path.class.to_s
57
79
 
58
- return Recls::Ximpl.canonicalise_path path
80
+ Recls::Ximpl.canonicalise_path path
59
81
  end
60
82
 
61
83
  # Derives a given path relative to an origin, unless the path is
62
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
63
94
  def self.derive_relative_path(origin, path)
64
95
 
65
- return Recls::Ximpl.derive_relative_path origin, path
96
+ Recls::Ximpl.derive_relative_path origin, path
66
97
  end
67
98
  end # module Recls
68
99
 
@@ -74,6 +105,42 @@ else
74
105
  require 'recls/combine_paths_1'
75
106
  end
76
107
 
108
+ module Recls
109
+
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
+ Recls::Ximpl.absolute_path? path
141
+ end
142
+ end # module Recls
143
+
77
144
  # ############################## end of file ############################# #
78
145
 
79
146
 
@@ -4,7 +4,7 @@
4
4
  # Purpose: Version for recls library
5
5
  #
6
6
  # Created: 14th February 2014
7
- # Updated: 10th April 2018
7
+ # Updated: 14th April 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
@@ -36,10 +36,15 @@
36
36
  # ######################################################################### #
37
37
 
38
38
 
39
+ =begin
40
+ =end
41
+
42
+ class Object; end # :nodoc:
43
+
39
44
  module Recls
40
45
 
41
46
  # Current version of the recls.Ruby library
42
- VERSION = '2.9.1'
47
+ VERSION = '2.10.0'
43
48
 
44
49
  private
45
50
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -47,7 +52,7 @@ module Recls
47
52
  VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
48
53
  VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
49
54
  VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
50
- end
55
+ end # module Recls
51
56
 
52
57
  # ############################## end of file ############################# #
53
58
 
@@ -1,15 +1,15 @@
1
1
  # ######################################################################### #
2
- # File: recls/ximpl/os.rb
2
+ # File: recls/ximpl/os.rb
3
3
  #
4
- # Purpose: Operating system internal implementation constructs for the
5
- # recls library.
4
+ # Purpose: Operating system internal implementation constructs for the
5
+ # recls library.
6
6
  #
7
- # Created: 16th February 2014
8
- # Updated: 27th August 2015
7
+ # Created: 16th February 2014
8
+ # Updated: 14th April 2019
9
9
  #
10
- # Author: Matthew Wilson
10
+ # Author: Matthew Wilson
11
11
  #
12
- # Copyright (c) 2012-2015, Matthew Wilson and Synesis Software
12
+ # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
13
13
  # All rights reserved.
14
14
  #
15
15
  # Redistribution and use in source and binary forms, with or without
@@ -37,11 +37,14 @@
37
37
  # ######################################################################### #
38
38
 
39
39
 
40
- module Recls
40
+ =begin
41
+ =end
41
42
 
42
- module Ximpl
43
+ module Recls # :nodoc:
43
44
 
44
- module OS
45
+ module Ximpl # :nodoc: all
46
+
47
+ module OS # :nodoc: all
45
48
 
46
49
  OS_IS_WINDOWS = (RUBY_PLATFORM =~ /(mswin|mingw|bccwin|wince)/i) ? true : false
47
50
 
@@ -77,9 +80,9 @@ module Recls
77
80
 
78
81
  return false
79
82
  end
80
- end
81
- end
82
- end
83
+ end # module OS
84
+ end # module Ximpl
85
+ end # module Recls
83
86
 
84
87
  # ############################## end of file ############################# #
85
88
 
@@ -1,14 +1,14 @@
1
1
  # ######################################################################### #
2
- # File: recls/ximpl/unix.rb
2
+ # File: recls/ximpl/unix.rb
3
3
  #
4
- # Purpose: UNIX-specific constructs for the recls library.
4
+ # Purpose: UNIX-specific constructs for the recls library.
5
5
  #
6
- # Created: 19th February 2014
7
- # Updated: 27th August 2015
6
+ # Created: 19th February 2014
7
+ # Updated: 14th April 2019
8
8
  #
9
- # Author: Matthew Wilson
9
+ # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2015, Matthew Wilson and Synesis Software
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,11 +38,14 @@
38
38
 
39
39
  require 'recls/ximpl/util'
40
40
 
41
- module Recls
41
+ =begin
42
+ =end
42
43
 
43
- module Ximpl
44
+ module Recls # :nodoc:
44
45
 
45
- class FileStat < File::Stat
46
+ module Ximpl # :nodoc: all
47
+
48
+ class FileStat < File::Stat # :nodoc:
46
49
 
47
50
  private
48
51
  def initialize(path)
@@ -73,9 +76,9 @@ module Recls
73
76
  Recls::Ximpl::FileStat.new(path)
74
77
 
75
78
  end
76
- end
77
- end
78
- end
79
+ end # class FileStat
80
+ end # module Ximpl
81
+ end # module Recls
79
82
 
80
83
  # ############################## end of file ############################# #
81
84
 
@@ -1,12 +1,12 @@
1
1
  # ######################################################################### #
2
- # File: recls/ximpl/util.rb
2
+ # File: recls/ximpl/util.rb
3
3
  #
4
- # Purpose: Internal implementation constructs for the recls library.
4
+ # Purpose: Internal implementation constructs for the recls library.
5
5
  #
6
- # Created: 24th July 2012
7
- # Updated: 21st Jannuary 2019
6
+ # Created: 24th July 2012
7
+ # Updated: 14th April 2019
8
8
  #
9
- # Author: Matthew Wilson
9
+ # Author: Matthew Wilson
10
10
  #
11
11
  # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
@@ -41,11 +41,14 @@ require 'recls/flags'
41
41
 
42
42
  require 'pathname'
43
43
 
44
- module Recls
44
+ =begin
45
+ =end
46
+
47
+ module Recls # :nodoc:
45
48
 
46
- module Ximpl
49
+ module Ximpl # :nodoc: all
47
50
 
48
- module Util
51
+ module Util # :nodoc: all
49
52
 
50
53
  def self.is_path_name_separator(c)
51
54
 
@@ -271,10 +274,6 @@ module Recls
271
274
 
272
275
  newParts = []
273
276
 
274
- =begin
275
- trailing_slash = parts.empty? ? nil : self.get_trailing_slash(parts[-1])
276
- =end
277
-
278
277
  lastSingleDots = nil
279
278
 
280
279
  path_is_rooted = nil
@@ -423,7 +422,7 @@ module Recls
423
422
 
424
423
  [ newParts.join(''), consume_basename ]
425
424
  end
426
- end
425
+ end # module Util
427
426
 
428
427
  # Canonicalises a path
429
428
  #
@@ -435,6 +434,8 @@ module Recls
435
434
  return nil if not path
436
435
  return '' if path.empty?
437
436
 
437
+ path = File.expand_path(path) if '~' == path[0].to_s
438
+
438
439
  f1_windows_root, f2_directory, f3_basename, dummy1, dummy2, directory_parts, dummy3 = Util.split_path(path)
439
440
 
440
441
  # suppress unused warnings
@@ -454,6 +455,39 @@ module Recls
454
455
  return "#{f1_windows_root}#{canonicalised_directory}#{f3_basename}"
455
456
  end
456
457
 
458
+ def self.absolute_path?(path)
459
+
460
+ case path
461
+ when nil
462
+
463
+ return nil
464
+ when ::String
465
+
466
+ return nil if path.empty?
467
+
468
+ path = File.expand_path(path) if '~' == path[0]
469
+ when ::Recls::Entry
470
+
471
+ return path
472
+ else
473
+
474
+ raise TypeError, "parameter path ('#{path}') is of type #{path.class} must be nil or an instance of #{::String} or #{::Recls::Entry}"
475
+ end
476
+
477
+ f1_windows_root, f2_directory, dummy1, dummy2, dummy3, dummy4, dummy5 = Util.split_path(path)
478
+
479
+ dummy1 = dummy2 = dummy3 = dummy4 = dummy5 = nil
480
+
481
+ unless f1_windows_root
482
+
483
+ return nil unless f2_directory
484
+
485
+ return nil unless Util.is_path_name_separator(f2_directory[0])
486
+ end
487
+
488
+ Recls::Ximpl.stat_prep(path, nil, Recls::DETAILS_LATER)
489
+ end
490
+
457
491
  # determines the absolute path of a given path
458
492
  def self.absolute_path(path, refdir = nil)
459
493
 
@@ -463,7 +497,10 @@ module Recls
463
497
  return nil
464
498
  when ::String
465
499
 
466
- path = path.to_s
500
+ path = File.expand_path(path) if '~' == path[0]
501
+ when ::Recls::Entry
502
+
503
+ return path.path
467
504
  else
468
505
 
469
506
  raise TypeError, "parameter path ('#{path}') is of type #{path.class} must be an instance of #{::String} or Recls::Entry"
@@ -649,10 +686,16 @@ module Recls
649
686
  path = self.canonicalise_path path
650
687
  origin = self.canonicalise_path origin
651
688
 
689
+ path = self.absolute_path path
690
+ origin = self.absolute_path origin
691
+
692
+ return path if /^\.[\\\/]*$/ =~ origin
693
+
652
694
  path_splits = Util.split_path(path)
653
695
  origin_splits = Util.split_path(origin)
654
696
 
655
697
  # if different windows root, then cannot provide relative
698
+
656
699
  if path_splits[0] and origin_splits[0]
657
700
 
658
701
  return path if path_splits[0] != origin_splits[0]
@@ -663,7 +706,7 @@ module Recls
663
706
  path_parts = path_splits[6]
664
707
  origin_parts = origin_splits[6]
665
708
 
666
- while true
709
+ loop do
667
710
 
668
711
  break if path_parts.empty?
669
712
  break if origin_parts.empty?
@@ -702,6 +745,8 @@ module Recls
702
745
  paths = [ paths ] unless ::Array === paths
703
746
  abs_ix = 0
704
747
 
748
+ paths = paths.map { |path| '~' == path[0].to_s ? File.expand_path(path) : path }
749
+
705
750
  paths.each_with_index do |path, index|
706
751
 
707
752
  dummy1, f2_directory, dummy2, dummy3, dummy4, dummy5, dummy6 = Util.split_path(path)
@@ -770,8 +815,27 @@ module Recls
770
815
  return []
771
816
  end
772
817
  end
773
- end
774
- end
818
+
819
+ def self.stat_prep(path, search_root, flags)
820
+
821
+ begin
822
+
823
+ Recls::Entry.new(path, Recls::Ximpl::FileStat.stat(path), search_root, flags)
824
+ rescue Errno::ENOENT, Errno::ENXIO => x
825
+
826
+ x = x # suppress warning
827
+
828
+ if 0 != (flags & Recls::DETAILS_LATER)
829
+
830
+ Recls::Entry.new(path, nil, search_root, flags)
831
+ else
832
+
833
+ nil
834
+ end
835
+ end
836
+ end
837
+ end # module Ximpl
838
+ end # module Recls
775
839
 
776
840
  # ############################## end of file ############################# #
777
841
 
@@ -1,14 +1,14 @@
1
1
  # ######################################################################### #
2
- # File: recls/ximpl/windows.rb
2
+ # File: recls/ximpl/windows.rb
3
3
  #
4
- # Purpose: Windows-specific constructs for the recls library.
4
+ # Purpose: Windows-specific constructs for the recls library.
5
5
  #
6
- # Created: 19th February 2014
7
- # Updated: 18th June 2016
6
+ # Created: 19th February 2014
7
+ # Updated: 14th April 2019
8
8
  #
9
- # Author: Matthew Wilson
9
+ # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2016, Matthew Wilson and Synesis Software
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,11 +38,14 @@
38
38
 
39
39
  require 'Win32API'
40
40
 
41
- module Recls
41
+ =begin
42
+ =end
42
43
 
43
- module Ximpl
44
+ module Recls # :nodoc:
44
45
 
45
- class FileStat < File::Stat
46
+ module Ximpl # :nodoc: all
47
+
48
+ class FileStat < File::Stat # :nodoc:
46
49
 
47
50
  private
48
51
  GetFileAttributes = Win32API.new('kernel32', 'GetFileAttributes', [ 'P' ], 'I')
@@ -70,7 +73,7 @@ module Recls
70
73
 
71
74
  BHFI_pack_string = 'LQQQLLLLLL'
72
75
 
73
- class ByHandleInformation
76
+ class ByHandleInformation # :nodoc:
74
77
 
75
78
  def initialize(path)
76
79
 
@@ -121,8 +124,10 @@ module Recls
121
124
  attributes = GetFileAttributes.call("#{path}")
122
125
 
123
126
  if 0xffffffff == attributes
127
+
124
128
  @attributes = 0
125
129
  else
130
+
126
131
  @attributes = attributes
127
132
  end
128
133
 
@@ -190,9 +195,9 @@ module Recls
190
195
 
191
196
  Recls::Ximpl::FileStat.new(path)
192
197
  end
193
- end
194
- end
195
- end
198
+ end # class FileStat
199
+ end # module Ximpl
200
+ end # module Recls
196
201
 
197
202
  # ############################## end of file ############################# #
198
203