symlink 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of symlink might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/symlink/constants.rb +17 -0
- data/lib/symlink/symlink.rb +332 -0
- data/lib/symlink/version/version.rb +17 -0
- data/lib/symlink.rb +1 -0
- data/symlink.gemspec +43 -0
- data/test/testing_symlink.rb +10 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 86ae7c3caaddb0bf6456b03bea0b0d8122882c50354f11d177d80e473c02b19f
|
4
|
+
data.tar.gz: fd063791d36e15c847a8f542b4641bfb88b1ec968943d4d471a99fd466707cb9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd8af7cac8269b46f49db8b78ccb79d9150a1623b0f96f52de3b13e2f0520542a806591c42aa2ce7b6f1c07d7f29a76ace3fecf7654f8c47498e8669842b3a6f
|
7
|
+
data.tar.gz: 96c5ae9d3eaebbab8471d55f37e65040804842cc8b26cd1dbefc6be2736225097849cb380d4dde92d7286444a8ee143e1bdb40c682f3a22bfe44442f24a9122b
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
class Symlink
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === NAMESPACE
|
9
|
+
# ========================================================================= #
|
10
|
+
NAMESPACE = inspect
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === USE_ABSOLUTE_SYMLINKING
|
14
|
+
# ========================================================================= #
|
15
|
+
USE_ABSOLUTE_SYMLINKING = false
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,332 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Symlink
|
6
|
+
#
|
7
|
+
# This general class will allow you to symlink one target to the other.
|
8
|
+
#
|
9
|
+
# Usage example:
|
10
|
+
# Symlink.new
|
11
|
+
# =========================================================================== #
|
12
|
+
# require 'symlink/symlink.rb'
|
13
|
+
# =========================================================================== #
|
14
|
+
require 'fileutils'
|
15
|
+
require 'opn'
|
16
|
+
# =========================================================================== #
|
17
|
+
# Add a few colours for support:
|
18
|
+
# =========================================================================== #
|
19
|
+
require 'colours/e/e.rb'
|
20
|
+
require 'colours/requires/require_sdir.rb'
|
21
|
+
require 'colours/requires/require_sfile.rb'
|
22
|
+
# =========================================================================== #
|
23
|
+
# And next pull in .rb files that are specific for Symlink:
|
24
|
+
# =========================================================================== #
|
25
|
+
require 'symlink/version/version.rb'
|
26
|
+
require 'symlink/constants.rb'
|
27
|
+
|
28
|
+
class Symlink # === Symlink
|
29
|
+
|
30
|
+
include Colours::E
|
31
|
+
|
32
|
+
# ========================================================================= #
|
33
|
+
# === initialize
|
34
|
+
# ========================================================================= #
|
35
|
+
def initialize(
|
36
|
+
old_existing_location,
|
37
|
+
new_location,
|
38
|
+
be_verbose = true,
|
39
|
+
run_already = true
|
40
|
+
)
|
41
|
+
reset
|
42
|
+
set_existing_location(old_existing_location) # from
|
43
|
+
set_new_location(new_location) # to
|
44
|
+
set_be_verbose(be_verbose) # Whether we are silent or not.
|
45
|
+
if block_given?
|
46
|
+
yielded = yield
|
47
|
+
if yielded.is_a? Hash
|
48
|
+
# === prepend_this_to_namespace
|
49
|
+
if yielded.has_key? :prepend_this_to_namespace
|
50
|
+
prepend_this_to_namespace(yielded.delete(:prepend_this_to_namespace))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
if run_already == :do_not_run_yet
|
55
|
+
run_already = false
|
56
|
+
end
|
57
|
+
run if run_already
|
58
|
+
end
|
59
|
+
|
60
|
+
# ========================================================================= #
|
61
|
+
# === reset (reset tag)
|
62
|
+
# ========================================================================= #
|
63
|
+
def reset
|
64
|
+
@use_absolute_symlinking = USE_ABSOLUTE_SYMLINKING
|
65
|
+
@use_opn = true
|
66
|
+
@be_verbose = true
|
67
|
+
@use_colours = true
|
68
|
+
@namespace = NAMESPACE # This can be changed.
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === prepend_this_to_namespace
|
73
|
+
# ========================================================================= #
|
74
|
+
def prepend_this_to_namespace(i)
|
75
|
+
@namespace.prepend(i.to_s.dup)
|
76
|
+
end
|
77
|
+
|
78
|
+
# ========================================================================= #
|
79
|
+
# === shall_we_use_colours?
|
80
|
+
#
|
81
|
+
# This method requires one mandatory argument.
|
82
|
+
# ========================================================================= #
|
83
|
+
def shall_we_use_colours?(true_or_false)
|
84
|
+
if true_or_false == false
|
85
|
+
disable_colours
|
86
|
+
else
|
87
|
+
enable_colours
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# ========================================================================= #
|
92
|
+
# === disable_colours
|
93
|
+
# ========================================================================= #
|
94
|
+
def disable_colours
|
95
|
+
@use_colours = false
|
96
|
+
end
|
97
|
+
|
98
|
+
# ========================================================================= #
|
99
|
+
# === enable_colours
|
100
|
+
# ========================================================================= #
|
101
|
+
def enable_colours
|
102
|
+
@use_colours = true
|
103
|
+
end
|
104
|
+
|
105
|
+
# ========================================================================= #
|
106
|
+
# === use_colours?
|
107
|
+
# ========================================================================= #
|
108
|
+
def use_colours?
|
109
|
+
@use_colours
|
110
|
+
end
|
111
|
+
|
112
|
+
# ========================================================================= #
|
113
|
+
# === use_absolute_symlinking
|
114
|
+
# ========================================================================= #
|
115
|
+
def use_absolute_symlinking
|
116
|
+
@use_absolute_symlinking = true
|
117
|
+
# ======================================================================= #
|
118
|
+
# We must also sync @existing_location.
|
119
|
+
# ======================================================================= #
|
120
|
+
set_existing_location(existing?)
|
121
|
+
end
|
122
|
+
|
123
|
+
# ========================================================================= #
|
124
|
+
# === set_be_verbose
|
125
|
+
# ========================================================================= #
|
126
|
+
def set_be_verbose(i)
|
127
|
+
@be_verbose = i
|
128
|
+
end
|
129
|
+
|
130
|
+
# ========================================================================= #
|
131
|
+
# === use_absolute_symlinking?
|
132
|
+
# ========================================================================= #
|
133
|
+
def use_absolute_symlinking?
|
134
|
+
@use_absolute_symlinking
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === set_existing_location
|
139
|
+
#
|
140
|
+
# This must be an existing file.
|
141
|
+
# ========================================================================= #
|
142
|
+
def set_existing_location(i = '')
|
143
|
+
i = i.first if i.is_a? Array
|
144
|
+
i = i.to_s.dup
|
145
|
+
i = rds(i)
|
146
|
+
if use_absolute_symlinking?
|
147
|
+
i = '../../../..'+i
|
148
|
+
end
|
149
|
+
@existing_location = i
|
150
|
+
end; alias set_old_target set_existing_location # === set_old_target
|
151
|
+
|
152
|
+
# ========================================================================= #
|
153
|
+
# === delete
|
154
|
+
#
|
155
|
+
# This will only ever delete files, not directories.
|
156
|
+
# ========================================================================= #
|
157
|
+
def delete(i)
|
158
|
+
i = i.dup if i.frozen?
|
159
|
+
i.strip!
|
160
|
+
if (rds(i) == '/')
|
161
|
+
ewarn 'We can never delete /'
|
162
|
+
else
|
163
|
+
File.delete(i)
|
164
|
+
end
|
165
|
+
end; alias remove delete # === remove
|
166
|
+
|
167
|
+
# ========================================================================= #
|
168
|
+
# === be_verbose?
|
169
|
+
# ========================================================================= #
|
170
|
+
def be_verbose?
|
171
|
+
@be_verbose
|
172
|
+
end
|
173
|
+
|
174
|
+
# ========================================================================= #
|
175
|
+
# === rds
|
176
|
+
# ========================================================================= #
|
177
|
+
def rds(i)
|
178
|
+
i.squeeze('/')
|
179
|
+
end
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === set_new_location
|
183
|
+
# ========================================================================= #
|
184
|
+
def set_new_location(i = '')
|
185
|
+
i = i.to_s.dup
|
186
|
+
i = rds(i)
|
187
|
+
@new_location = i
|
188
|
+
end; alias set_new_target set_new_location # === set_new_target
|
189
|
+
|
190
|
+
# ========================================================================= #
|
191
|
+
# === old?
|
192
|
+
# ========================================================================= #
|
193
|
+
def old?
|
194
|
+
@existing_location
|
195
|
+
end; alias existing? old? # === existing?
|
196
|
+
alias old_target? old? # === old_target?
|
197
|
+
alias from? old? # === from?
|
198
|
+
|
199
|
+
# ========================================================================= #
|
200
|
+
# === new?
|
201
|
+
# ========================================================================= #
|
202
|
+
def new?
|
203
|
+
@new_location
|
204
|
+
end; alias new_target? new? # === new_target?
|
205
|
+
alias to? new? # === to?
|
206
|
+
|
207
|
+
# ========================================================================= #
|
208
|
+
# === do_symlink
|
209
|
+
#
|
210
|
+
# This is the actual method that will perform the symlink-operation in
|
211
|
+
# question.
|
212
|
+
# ========================================================================= #
|
213
|
+
def do_symlink(
|
214
|
+
be_verbose = be_verbose?
|
215
|
+
)
|
216
|
+
new_target = new_target?
|
217
|
+
old_target = old_target?
|
218
|
+
# ======================================================================= #
|
219
|
+
# We must first check whether the target at new? exists or whether
|
220
|
+
# it does not.
|
221
|
+
# ======================================================================= #
|
222
|
+
if File.exist? new_target
|
223
|
+
# ===================================================================== #
|
224
|
+
# === Append a '/' if necessary
|
225
|
+
# ===================================================================== #
|
226
|
+
if File.directory?(new_target) and File.directory?(old_target) and
|
227
|
+
!old_target.end_with?('/')
|
228
|
+
set_old_target("#{old_target}/")
|
229
|
+
old_target = old_target?
|
230
|
+
end
|
231
|
+
old_target = old_target.dup
|
232
|
+
# if File.directory?(new_target) and File.directory?(old_target) and
|
233
|
+
# !( File.basename(new_target) == File.basename(old_target) )
|
234
|
+
# # =================================================================== #
|
235
|
+
# # This is specifically used to change
|
236
|
+
# # /home/Programs/Htslib/1.12/include/htslib/ and
|
237
|
+
# # /usr/include/ into /usr/include/htslib/.
|
238
|
+
# # =================================================================== #
|
239
|
+
# new_target << rds("#{File.basename(old_target)}")
|
240
|
+
# end
|
241
|
+
#^^^ this does not work correctly... in April 2021.
|
242
|
+
if File.directory?(new_target) and File.file?(old_target) # Silent renaming then.
|
243
|
+
_ = new_target+File.basename(old_target)
|
244
|
+
set_new_target(_)
|
245
|
+
end
|
246
|
+
if File.symlink? new_target
|
247
|
+
delete(new_target)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
if be_verbose
|
251
|
+
opnn if use_opn?
|
252
|
+
e 'Symlinking '+sfile(existing?)+' into '+sfile(new_target)+'.'
|
253
|
+
end
|
254
|
+
begin
|
255
|
+
File.symlink(existing?, new_target)
|
256
|
+
rescue Errno::ENOENT => error # No such file or directory
|
257
|
+
opnn if use_opn?
|
258
|
+
e "Can not symlink - no such file exists, at `#{sfile(new_target)}`."
|
259
|
+
pp error
|
260
|
+
rescue Errno::EEXIST => error # The file does not exist.
|
261
|
+
opnn if use_opn?
|
262
|
+
e "Can not symlink - the file at `#{sfile(new_target)}` already exists."
|
263
|
+
pp error
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# ========================================================================= #
|
268
|
+
# === do_not_use_opn
|
269
|
+
# ========================================================================= #
|
270
|
+
def do_not_use_opn
|
271
|
+
@use_opn = false
|
272
|
+
end; alias disable_opn do_not_use_opn # === disable_opn
|
273
|
+
|
274
|
+
# ========================================================================= #
|
275
|
+
# === use_opn?
|
276
|
+
# ========================================================================= #
|
277
|
+
def use_opn?
|
278
|
+
@use_opn
|
279
|
+
end
|
280
|
+
|
281
|
+
# ========================================================================= #
|
282
|
+
# === namespace?
|
283
|
+
# ========================================================================= #
|
284
|
+
def namespace?
|
285
|
+
@namespace
|
286
|
+
end
|
287
|
+
|
288
|
+
# ========================================================================= #
|
289
|
+
# === sfile
|
290
|
+
# ========================================================================= #
|
291
|
+
def sfile(i)
|
292
|
+
return Colours.sfile(i) if use_colours?
|
293
|
+
i
|
294
|
+
end
|
295
|
+
|
296
|
+
# ========================================================================= #
|
297
|
+
# === sdir
|
298
|
+
# ========================================================================= #
|
299
|
+
def sdir(i)
|
300
|
+
return Colours.sdir(i) if use_colours?
|
301
|
+
i
|
302
|
+
end
|
303
|
+
|
304
|
+
# ========================================================================= #
|
305
|
+
# === opnn
|
306
|
+
# ========================================================================= #
|
307
|
+
def opnn
|
308
|
+
Opn.opn(
|
309
|
+
namespace: @namespace,
|
310
|
+
use_colours: use_colours?
|
311
|
+
)
|
312
|
+
end
|
313
|
+
|
314
|
+
# ========================================================================= #
|
315
|
+
# === run (run tag)
|
316
|
+
# ========================================================================= #
|
317
|
+
def run
|
318
|
+
do_symlink
|
319
|
+
end
|
320
|
+
|
321
|
+
# ========================================================================= #
|
322
|
+
# === Symlink[]
|
323
|
+
# ========================================================================= #
|
324
|
+
def self.[](old, new)
|
325
|
+
self.new(old, new)
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
if __FILE__ == $PROGRAM_NAME
|
331
|
+
Symlink.new(ARGV.first, ARGV[1])
|
332
|
+
end # rubysymlink /Depot/j/foo.mp3 /Depot/j/bar.mp3
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
class Symlink
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === VERSION
|
9
|
+
# ========================================================================= #
|
10
|
+
VERSION = '0.0.27'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === LAST_UPDATE
|
14
|
+
# ========================================================================= #
|
15
|
+
LAST_UPDATE = '15.08.2021'
|
16
|
+
|
17
|
+
end
|
data/lib/symlink.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'symlink/symlink.rb'
|
data/symlink.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Gemspec for Project Symlink.
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'symlink/version/version.rb'
|
5
|
+
require 'roebe'
|
6
|
+
|
7
|
+
Gem::Specification.new { |s|
|
8
|
+
|
9
|
+
s.name = 'symlink'
|
10
|
+
s.version = Symlink::VERSION
|
11
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
12
|
+
|
13
|
+
DESCRIPTION = <<-EOF
|
14
|
+
|
15
|
+
This library is called symlink. It can be used to symlink
|
16
|
+
files or directories, from within ruby.
|
17
|
+
|
18
|
+
General syntax is:
|
19
|
+
|
20
|
+
Symlink.new(from, to)
|
21
|
+
|
22
|
+
EOF
|
23
|
+
|
24
|
+
s.summary = DESCRIPTION
|
25
|
+
s.description = DESCRIPTION
|
26
|
+
|
27
|
+
s.authors = ['Robert A. Heiler']
|
28
|
+
s.email = Roebe.email?
|
29
|
+
s.files = Dir['**/*']
|
30
|
+
|
31
|
+
s.license = 'MIT'
|
32
|
+
|
33
|
+
s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
|
34
|
+
s.required_rubygems_version = '>= '+Gem::VERSION
|
35
|
+
s.rubygems_version = '>= '+Gem::VERSION
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# Dependencies for the project:
|
39
|
+
# ========================================================================= #
|
40
|
+
s.add_dependency 'colours'
|
41
|
+
s.add_dependency 'opn'
|
42
|
+
|
43
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
require 'symlink'
|
6
|
+
require 'colours/autoinclude'
|
7
|
+
Symlink[
|
8
|
+
'/Programs/Applewmproto/1.4.2/',
|
9
|
+
'/Programs/Applewmproto/Current'
|
10
|
+
] # $RSRC/symlink/test/testing_symlink.rb
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: symlink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.27
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert A. Heiler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colours
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: opn
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |2+
|
42
|
+
|
43
|
+
This library is called symlink. It can be used to symlink
|
44
|
+
files or directories, from within ruby.
|
45
|
+
|
46
|
+
General syntax is:
|
47
|
+
|
48
|
+
Symlink.new(from, to)
|
49
|
+
|
50
|
+
email: shevy@inbox.lt
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- lib/symlink.rb
|
56
|
+
- lib/symlink/constants.rb
|
57
|
+
- lib/symlink/symlink.rb
|
58
|
+
- lib/symlink/version/version.rb
|
59
|
+
- symlink.gemspec
|
60
|
+
- test/testing_symlink.rb
|
61
|
+
homepage:
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 2.5.8
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 3.2.24
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.2.24
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: 'This library is called symlink. It can be used to symlink files or directories,
|
84
|
+
from within ruby. General syntax is: Symlink.new(from, to)'
|
85
|
+
test_files: []
|
86
|
+
...
|