libpath-ruby 0.2.2 → 0.2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +33 -0
- data/README.md +25 -8
- data/examples/path_from_arg0.md +43 -43
- data/examples/path_from_arg0.rb +25 -23
- data/lib/libpath/constants/unix.rb +74 -74
- data/lib/libpath/constants/windows.rb +75 -75
- data/lib/libpath/constants.rb +20 -20
- data/lib/libpath/diagnostics/parameter_checking.rb +27 -26
- data/lib/libpath/diagnostics.rb +1 -1
- data/lib/libpath/exceptions/libpath_base_exception.rb +20 -21
- data/lib/libpath/exceptions/malformed_name_exception.rb +27 -27
- data/lib/libpath/exceptions.rb +1 -1
- data/lib/libpath/form/unix.rb +118 -118
- data/lib/libpath/form/windows.rb +228 -214
- data/lib/libpath/form.rb +20 -21
- data/lib/libpath/internal_/array.rb +57 -57
- data/lib/libpath/internal_/platform.rb +30 -31
- data/lib/libpath/internal_/string.rb +25 -20
- data/lib/libpath/internal_/unix/form.rb +124 -119
- data/lib/libpath/internal_/windows/drive.rb +80 -75
- data/lib/libpath/internal_/windows/form.rb +205 -194
- data/lib/libpath/libpath.rb +4 -1
- data/lib/libpath/path/unix.rb +120 -118
- data/lib/libpath/path/windows.rb +126 -124
- data/lib/libpath/path.rb +21 -21
- data/lib/libpath/util/unix.rb +261 -261
- data/lib/libpath/util/windows.rb +403 -403
- data/lib/libpath/util.rb +20 -20
- data/lib/libpath/version.rb +25 -26
- data/lib/libpath.rb +1 -1
- data/test/performance/benchmark_drive_letter.rb +50 -10
- data/test/performance/benchmark_gsub_string_or_regex.rb +27 -23
- data/test/performance/benchmark_rindex2.rb +56 -48
- data/test/performance/benchmark_split.rb +16 -10
- data/test/unit/compare/ts_all.rb +4 -4
- data/test/unit/equate/ts_all.rb +4 -4
- data/test/unit/equate/unix/ts_all.rb +4 -4
- data/test/unit/equate/windows/ts_all.rb +4 -4
- data/test/unit/exceptions/tc_libpath_base_exception.rb +10 -8
- data/test/unit/exceptions/tc_malformed_name_exception.rb +14 -12
- data/test/unit/exceptions/ts_all.rb +4 -4
- data/test/unit/form/tc_absolute_functions.rb +242 -240
- data/test/unit/form/ts_all.rb +4 -4
- data/test/unit/form/unix/tc_absolute_functions.rb +158 -155
- data/test/unit/form/unix/ts_all.rb +4 -4
- data/test/unit/form/windows/tc_absolute_functions.rb +628 -625
- data/test/unit/form/windows/ts_all.rb +4 -4
- data/test/unit/internal_/tc_array.rb +36 -32
- data/test/unit/internal_/ts_all.rb +4 -4
- data/test/unit/internal_/unix/form/tc_slash_functions.rb +38 -35
- data/test/unit/internal_/unix/form/ts_all.rb +4 -4
- data/test/unit/internal_/unix/tc_split_path.rb +387 -384
- data/test/unit/internal_/unix/ts_all.rb +4 -4
- data/test/unit/internal_/windows/form/tc_get_windows_volume.rb +157 -153
- data/test/unit/internal_/windows/form/tc_slash_functions.rb +39 -35
- data/test/unit/internal_/windows/form/ts_all.rb +4 -4
- data/test/unit/internal_/windows/tc_split_path.rb +874 -869
- data/test/unit/internal_/windows/ts_all.rb +4 -4
- data/test/unit/parse/ts_all.rb +4 -4
- data/test/unit/path/tc_path.rb +732 -732
- data/test/unit/path/ts_all.rb +4 -4
- data/test/unit/path/unix/tc_path.rb +544 -540
- data/test/unit/path/unix/ts_all.rb +4 -4
- data/test/unit/path/windows/tc_path.rb +608 -603
- data/test/unit/path/windows/ts_all.rb +4 -4
- data/test/unit/tc_version.rb +25 -22
- data/test/unit/ts_all.rb +4 -4
- data/test/unit/util/tc_combine_paths.rb +110 -105
- data/test/unit/util/tc_derive_relative_path.rb +8 -3
- data/test/unit/util/tc_make_path_canonical.rb +142 -138
- data/test/unit/util/ts_all.rb +4 -4
- data/test/unit/util/unix/tc_combine_paths.rb +38 -34
- data/test/unit/util/unix/tc_derive_relative_path.rb +80 -75
- data/test/unit/util/unix/tc_make_path_absolute.rb +74 -70
- data/test/unit/util/unix/tc_make_path_canonical.rb +95 -90
- data/test/unit/util/unix/ts_all.rb +4 -4
- data/test/unit/util/windows/tc_combine_paths.rb +82 -77
- data/test/unit/util/windows/tc_derive_relative_path.rb +98 -93
- data/test/unit/util/windows/tc_make_path_absolute.rb +105 -101
- data/test/unit/util/windows/tc_make_path_canonical.rb +158 -153
- data/test/unit/util/windows/ts_all.rb +4 -4
- metadata +9 -8
data/lib/libpath/util/unix.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
# ######################################################################## #
|
3
|
-
# File:
|
3
|
+
# File: libpath/util/unix.rb
|
4
4
|
#
|
5
|
-
# Purpose:
|
5
|
+
# Purpose: LibPath::Util::Unix module
|
6
6
|
#
|
7
|
-
# Created:
|
8
|
-
# Updated:
|
7
|
+
# Created: 14th January 2019
|
8
|
+
# Updated: 7th April 2024
|
9
9
|
#
|
10
|
-
# Home:
|
10
|
+
# Home: http://github.com/synesissoftware/libpath.Ruby
|
11
11
|
#
|
12
|
-
# Author:
|
12
|
+
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
14
15
|
# Copyright (c) 2019, Matthew Wilson and Synesis Software
|
15
16
|
# All rights reserved.
|
16
17
|
#
|
@@ -44,371 +45,370 @@
|
|
44
45
|
# ######################################################################## #
|
45
46
|
|
46
47
|
|
47
|
-
|
48
48
|
=begin
|
49
49
|
=end
|
50
50
|
|
51
|
-
|
52
51
|
require 'libpath/diagnostics'
|
53
52
|
require 'libpath/form/unix'
|
54
53
|
require 'libpath/internal_/array'
|
55
54
|
require 'libpath/internal_/unix/form'
|
56
55
|
|
57
|
-
module LibPath # :nodoc:
|
58
|
-
module Util # :nodoc:
|
59
|
-
module Unix # :nodoc:
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
module
|
57
|
+
module LibPath
|
58
|
+
module Util
|
59
|
+
module Unix
|
60
|
+
|
61
|
+
# Module defining instance functions that will be included and extended into
|
62
|
+
# any class or module including/extending module LibPath::Util::Unix
|
63
|
+
module LibPath_Util_Unix_Methods
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
# Combines a number of path parts into a single path, ignoring any parts
|
66
|
+
# that are preceded by an absolute part
|
67
|
+
#
|
68
|
+
# NOTE: The behaviour of this method is undefined if any of the parts
|
69
|
+
# are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
|
70
|
+
def combine_paths *args, **options
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
_Form_Unix = Form::Unix
|
73
|
+
_Internal_Unix_Form = Internal_::Unix::Form
|
74
74
|
|
75
|
-
|
75
|
+
args.each_with_index { |arg, index| Diagnostics.check_string_parameter(arg, "arg#{index}", allow_nil: true) } if $DEBUG
|
76
76
|
|
77
|
-
|
77
|
+
if options[:elide_single_dots]
|
78
78
|
|
79
|
-
|
79
|
+
args = args.map do |arg|
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
case arg
|
82
|
+
when '.', './'
|
83
83
|
|
84
|
-
|
85
|
-
|
84
|
+
nil
|
85
|
+
else
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
arg
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
91
|
|
92
|
-
|
92
|
+
args = args.reject { |arg| arg.nil? || arg.empty? }
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
case args.size
|
95
|
+
when 0
|
96
96
|
|
97
|
-
|
98
|
-
|
97
|
+
''
|
98
|
+
when 1
|
99
99
|
|
100
|
-
|
101
|
-
|
100
|
+
args[0]
|
101
|
+
else
|
102
102
|
|
103
|
-
|
104
|
-
|
103
|
+
rix = args.rindex { |arg| arg && _Form_Unix.path_is_absolute?(arg) }
|
104
|
+
rix ||= 0
|
105
105
|
|
106
|
-
|
106
|
+
els = args[rix..-1]
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
File.join(*els)
|
109
|
+
end
|
110
|
+
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
112
|
+
# Obtains the form of the given +path+ relative to the given +origin+
|
113
|
+
#
|
114
|
+
# NOTE: The behaviour of this method is undefined if any of the parts
|
115
|
+
# are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
|
116
|
+
#
|
117
|
+
# === Signature
|
118
|
+
#
|
119
|
+
# * *Options:*
|
120
|
+
# +:home+:: (String)
|
121
|
+
# +:locator+:: (boolean)
|
122
|
+
# +:pwd+:: (String)
|
123
|
+
def derive_relative_path origin, path, **options
|
124
124
|
|
125
|
-
|
126
|
-
|
125
|
+
return path if origin.nil? || origin.empty?
|
126
|
+
return path if path.nil? || path.empty?
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
_Form_Unix = Form::Unix
|
129
|
+
_Util_Unix = Util::Unix
|
130
|
+
_Internal_Unix_Form = Internal_::Unix::Form
|
131
131
|
|
132
|
-
|
132
|
+
_MPA_COMMON_OPTIONS = %i{ home locator pwd }
|
133
133
|
|
134
|
-
|
134
|
+
tr_sl = _Internal_Unix_Form.get_trailing_slash(path)
|
135
135
|
|
136
|
-
|
137
|
-
|
136
|
+
origin = _Util_Unix.make_path_canonical(origin)
|
137
|
+
path = _Util_Unix.make_path_canonical(path)
|
138
138
|
|
139
|
-
|
140
|
-
|
139
|
+
return '.' + tr_sl.to_s if origin == path
|
140
|
+
return path if '.' == origin || './' == origin
|
141
141
|
|
142
|
-
|
143
|
-
|
142
|
+
o_is_abs = _Form_Unix.path_is_absolute?(origin)
|
143
|
+
p_is_abs = _Form_Unix.path_is_absolute?(path)
|
144
144
|
|
145
|
-
|
145
|
+
if o_is_abs != p_is_abs || './' == path
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
origin = _Util_Unix.make_path_absolute(origin, make_canonical: true, **options.select { |k| _MPA_COMMON_OPTIONS.include?(k) })
|
148
|
+
path = _Util_Unix.make_path_absolute(path, make_canonical: true, **options.select { |k| _MPA_COMMON_OPTIONS.include?(k) })
|
149
|
+
end
|
150
150
|
|
151
|
-
|
152
|
-
|
151
|
+
origin = _Internal_Unix_Form.trim_trailing_slash(origin) unless origin.size < 2
|
152
|
+
path = _Internal_Unix_Form.trim_trailing_slash(path) if tr_sl && path.size > 1
|
153
153
|
|
154
154
|
|
155
|
-
|
156
|
-
|
155
|
+
_, _, _, o3_basename, _, _, o6_parts, _ = _Internal_Unix_Form.split_path(origin)
|
156
|
+
_, _, _, p3_basename, _, _, p6_parts, _ = _Internal_Unix_Form.split_path(path)
|
157
157
|
|
158
|
-
|
159
|
-
|
158
|
+
o_parts = o6_parts
|
159
|
+
o_parts << o3_basename if o3_basename && '.' != o3_basename
|
160
160
|
|
161
|
-
|
162
|
-
|
161
|
+
p_parts = p6_parts
|
162
|
+
p_parts << p3_basename if p3_basename && '.' != p3_basename
|
163
163
|
|
164
164
|
|
165
|
-
|
165
|
+
while true
|
166
166
|
|
167
|
-
|
168
|
-
|
167
|
+
break if o_parts.empty?
|
168
|
+
break if p_parts.empty?
|
169
169
|
|
170
|
-
|
171
|
-
|
170
|
+
o_part = o_parts[0]
|
171
|
+
p_part = p_parts[0]
|
172
172
|
|
173
|
-
|
173
|
+
if 1 == o_parts.size || 1 == p_parts.size
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
175
|
+
o_part = _Internal_Unix_Form.append_trailing_slash o_part
|
176
|
+
p_part = _Internal_Unix_Form.append_trailing_slash p_part
|
177
|
+
end
|
178
178
|
|
179
|
-
|
179
|
+
if o_part == p_part
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
181
|
+
o_parts.shift
|
182
|
+
p_parts.shift
|
183
|
+
else
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
break
|
186
|
+
end
|
187
|
+
end
|
188
188
|
|
189
189
|
|
190
|
-
|
190
|
+
return '.' + tr_sl.to_s if 0 == (o_parts.size + p_parts.size)
|
191
191
|
|
192
|
-
|
192
|
+
return o_parts.map { |rp| '..' }.join('/') + (tr_sl || (o_parts.size != 0 ? '/' : nil)).to_s if p_parts.empty?
|
193
193
|
|
194
194
|
|
195
|
-
|
196
|
-
|
197
|
-
|
195
|
+
ar = [ '..' ] * o_parts.size + p_parts
|
196
|
+
last = ar.pop
|
197
|
+
ar = ar.map { |el| _Internal_Unix_Form.append_trailing_slash(el) }
|
198
198
|
|
199
|
-
|
200
|
-
|
199
|
+
ar.join + last.to_s + tr_sl.to_s
|
200
|
+
end
|
201
201
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
202
|
+
# Returns a "compare path" for the given absolute path
|
203
|
+
#
|
204
|
+
# A compare path is one that would refer definitely to a given entry,
|
205
|
+
# regardless of such operating system-specific issues such as
|
206
|
+
# case-insensitivity
|
207
|
+
#
|
208
|
+
# NOTE: the function does not make +path+ absolute. That is up to the
|
209
|
+
# caller if required
|
210
|
+
#
|
211
|
+
# NOTE: The behaviour of this method is undefined if any of the parts
|
212
|
+
# are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
|
213
|
+
#
|
214
|
+
# === Signature
|
215
|
+
#
|
216
|
+
# * *Parameters:*
|
217
|
+
# - +path+:: (String) The path whose definitive equivalent is to be
|
218
|
+
# obtained
|
219
|
+
# - +options+:: (Hash) options
|
220
|
+
#
|
221
|
+
# * *Options:*
|
222
|
+
# For reasons of compatibility (with the Windows version) no options
|
223
|
+
# are currently supported; none are proscribed.
|
224
|
+
def make_compare_path path, **options
|
225
225
|
|
226
|
-
|
227
|
-
|
226
|
+
path
|
227
|
+
end
|
228
228
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
229
|
+
#
|
230
|
+
# NOTE: The behaviour of this method is undefined if any of the parts
|
231
|
+
# are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
|
232
|
+
#
|
233
|
+
# === Signature
|
234
|
+
#
|
235
|
+
# * *Parameters:*
|
236
|
+
# - +path+:: (String) The path to be evaluated. May not be +nil+
|
237
|
+
# - +options+:: (Hash) Options that moderate the behaviour of the
|
238
|
+
# function
|
239
|
+
#
|
240
|
+
# * *Options:*
|
241
|
+
# - +:home+:: (String) A specific home to assume, which means that the
|
242
|
+
# +locator+'s +home+ method will not be invoked
|
243
|
+
# - +:locator+:: (object) An object that provides the methods
|
244
|
+
# +pwd+ and +home+, as needed. This allows for mocking. If not
|
245
|
+
# given, then the functions +Dir::pwd+ and +Dir::home+ are used
|
246
|
+
# - +:make_canonical+:: (boolean) Determines whether canonicalisation
|
247
|
+
# is conducted on the result
|
248
|
+
# - +:pwd+:: (String) A specific directory to assume, which means that
|
249
|
+
# the +locator+'s +pwd+ method will not be invoked
|
250
|
+
def make_path_absolute path, **options
|
251
251
|
|
252
|
-
|
253
|
-
|
252
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
253
|
+
Diagnostics.check_options(options, known: %i{ home locator make_canonical pwd }) if $DEBUG
|
254
254
|
|
255
|
-
|
255
|
+
return path if path.nil? || path.empty?
|
256
256
|
|
257
|
-
|
257
|
+
r = nil
|
258
258
|
|
259
|
-
|
260
|
-
|
259
|
+
case path[0]
|
260
|
+
when '/'
|
261
261
|
|
262
|
-
|
263
|
-
|
262
|
+
r = path
|
263
|
+
when '~'
|
264
264
|
|
265
|
-
|
266
|
-
|
265
|
+
case path[1]
|
266
|
+
when nil, '/'
|
267
267
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
268
|
+
home = nil
|
269
|
+
home ||= options[:home]
|
270
|
+
home ||= options[:locator].home if options.has_key?(:locator)
|
271
|
+
home ||= Dir.home
|
272
272
|
|
273
|
-
|
274
|
-
|
275
|
-
|
273
|
+
r = File.join(home, path[2..-1].to_s)
|
274
|
+
end
|
275
|
+
end
|
276
276
|
|
277
|
-
|
277
|
+
unless r
|
278
278
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
279
|
+
pwd = nil
|
280
|
+
pwd ||= options[:pwd]
|
281
|
+
pwd ||= options[:locator].pwd if options.has_key?(:locator)
|
282
|
+
pwd ||= Dir.pwd
|
283
283
|
|
284
|
-
|
285
|
-
|
284
|
+
r = File.join(pwd, path)
|
285
|
+
end
|
286
286
|
|
287
|
-
|
287
|
+
r ||= path
|
288
288
|
|
289
|
-
|
289
|
+
r = make_path_canonical r if options[:make_canonical]
|
290
290
|
|
291
|
-
|
292
|
-
|
291
|
+
return r
|
292
|
+
end
|
293
293
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
294
|
+
# Converts a path into canonical form, which is to say that all possible
|
295
|
+
# dots directory parts are removed:
|
296
|
+
#
|
297
|
+
# - single-dot (trailing) parts - '???/.' are converted to '???/' (where
|
298
|
+
# ??? represents 0+ other characters);
|
299
|
+
# - single-dot parts - './' - are all removed
|
300
|
+
# - double-dot parts - '../' - are removed where they follow a non-dots
|
301
|
+
# directory part, or where they follow the root
|
302
|
+
#
|
303
|
+
# NOTE: The behaviour of this method is undefined if any of the parts
|
304
|
+
# are malformed. See +::LibPath::Form::Windows::name_is_malformed?+
|
305
|
+
#
|
306
|
+
# === Signature
|
307
|
+
#
|
308
|
+
# * *Parameters:*
|
309
|
+
# - +path+:: (String) The path to be evaluated. May not be +nil+
|
310
|
+
def make_path_canonical path, **options
|
311
311
|
|
312
|
-
|
312
|
+
Diagnostics.check_string_parameter(path, "path") if $DEBUG
|
313
313
|
|
314
|
-
|
314
|
+
return path unless '.' == path[-1] || path.include?('./') || path.include?('//')
|
315
315
|
|
316
|
-
|
317
|
-
|
316
|
+
_Form = ::LibPath::Internal_::Unix::Form
|
317
|
+
_Array = ::LibPath::Internal_::Array
|
318
318
|
|
319
|
-
|
319
|
+
path = path[0...-1] if '.' == path[-1] && '/' == path[-2]
|
320
320
|
|
321
321
|
|
322
|
-
|
322
|
+
f0_path, _, f2_dir, f3_basename, _, _, f6_dir_parts, _ = _Form.split_path path
|
323
323
|
|
324
|
-
|
324
|
+
if f6_dir_parts.empty?
|
325
325
|
|
326
|
-
|
327
|
-
|
326
|
+
case f3_basename
|
327
|
+
when '.'
|
328
328
|
|
329
|
-
|
330
|
-
|
329
|
+
return './'
|
330
|
+
when '..'
|
331
331
|
|
332
|
-
|
333
|
-
|
332
|
+
return '../'
|
333
|
+
else
|
334
334
|
|
335
|
-
|
336
|
-
|
337
|
-
|
335
|
+
return f0_path
|
336
|
+
end
|
337
|
+
end
|
338
338
|
|
339
|
-
|
340
|
-
|
339
|
+
case f3_basename
|
340
|
+
when '.', '..'
|
341
341
|
|
342
|
-
|
343
|
-
|
344
|
-
|
342
|
+
f6_dir_parts << f3_basename + '/'
|
343
|
+
basename = nil
|
344
|
+
else
|
345
345
|
|
346
|
-
|
347
|
-
|
346
|
+
basename = f3_basename
|
347
|
+
end
|
348
348
|
|
349
|
-
|
349
|
+
is_rooted = '/' == f2_dir[0]
|
350
350
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
351
|
+
new_parts = f6_dir_parts.dup
|
352
|
+
new_parts.reject! { |p| './' == p }
|
353
|
+
ix_nodots = new_parts.index { |p| '../' != p } || new_parts.size
|
354
|
+
ix_2dots = _Array.index(new_parts, '../', ix_nodots)
|
355
355
|
|
356
|
-
|
356
|
+
return "#{new_parts.join}#{basename}" unless new_parts.size != f6_dir_parts.size || ix_2dots
|
357
357
|
|
358
|
-
|
358
|
+
while (ix_2dots || 0) > 0
|
359
359
|
|
360
|
-
|
361
|
-
|
360
|
+
new_parts.delete_at(ix_2dots - 0)
|
361
|
+
new_parts.delete_at(ix_2dots - 1) if ix_2dots != 1 || !is_rooted
|
362
362
|
|
363
|
-
|
364
|
-
|
365
|
-
|
363
|
+
ix_nodots = new_parts.index { |p| '../' != p } or break
|
364
|
+
ix_2dots = _Array.index(new_parts, '../', ix_nodots)
|
365
|
+
end
|
366
366
|
|
367
|
-
|
367
|
+
if new_parts.empty? && (basename || '').empty?
|
368
368
|
|
369
|
-
|
370
|
-
|
369
|
+
case f3_basename
|
370
|
+
when nil, '.', '..'
|
371
371
|
|
372
|
-
|
373
|
-
|
372
|
+
return './'
|
373
|
+
else
|
374
374
|
|
375
|
-
|
376
|
-
|
377
|
-
|
375
|
+
return '.'
|
376
|
+
end
|
377
|
+
end
|
378
378
|
|
379
|
-
|
380
|
-
|
381
|
-
end # module LibPath_Util_Unix_Methods
|
379
|
+
return new_parts.join('') + basename.to_s
|
380
|
+
end
|
381
|
+
end # module LibPath_Util_Unix_Methods
|
382
382
|
|
383
|
-
# @!visibility private
|
384
|
-
def self.extended receiver # :nodoc:
|
383
|
+
# @!visibility private
|
384
|
+
def self.extended receiver # :nodoc:
|
385
385
|
|
386
|
-
|
386
|
+
receiver.class_eval do
|
387
387
|
|
388
|
-
|
389
|
-
|
388
|
+
extend LibPath_Util_Unix_Methods
|
389
|
+
end
|
390
390
|
|
391
|
-
|
392
|
-
end
|
391
|
+
$stderr.puts "#{receiver} extended by #{LibPath_Util_Unix_Methods}" if $DEBUG
|
392
|
+
end
|
393
393
|
|
394
|
-
# @!visibility private
|
395
|
-
def self.included receiver # :nodoc:
|
394
|
+
# @!visibility private
|
395
|
+
def self.included receiver # :nodoc:
|
396
396
|
|
397
|
-
|
397
|
+
receiver.class_eval do
|
398
398
|
|
399
|
-
|
400
|
-
|
399
|
+
include LibPath_Util_Unix_Methods
|
400
|
+
end
|
401
401
|
|
402
|
-
|
403
|
-
end
|
402
|
+
$stderr.puts "#{receiver} included #{LibPath_Util_Unix_Methods}" if $DEBUG
|
403
|
+
end
|
404
404
|
|
405
|
-
extend LibPath_Util_Unix_Methods
|
406
|
-
include LibPath_Util_Unix_Methods
|
405
|
+
extend LibPath_Util_Unix_Methods
|
406
|
+
include LibPath_Util_Unix_Methods
|
407
407
|
|
408
408
|
end # module Unix
|
409
409
|
end # module Util
|
410
410
|
end # module LibPath
|
411
411
|
|
412
|
-
# ############################## end of file ############################# #
|
413
412
|
|
413
|
+
# ############################## end of file ############################# #
|
414
414
|
|