posix-fileutils 0.1.1 → 0.1.2
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.
- checksums.yaml +8 -8
- data/lib/posix-fileutils/fileutils.rb +64 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWM5MDI2MWIxODlhNGY4MTM0YTY1YmY3YzY3NzYwMjNiOWQyMmM3Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2M3ZjdlNzRjMTMxYWVlY2QwZjZkM2M5Mjg0NzkxZTY3YTQ3YzcxNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWI5OGUzNTY4MDQ5OGRiMzQ4OGFkZjZjODZkMGMzMTIyMzY4ZWI1YzhmYWM2
|
10
|
+
MWNhNDViZTg5ZjExYWNjNTUxYWE5MmVmMmFiZDdlNTZkNGEyNjA1MjZjOWVh
|
11
|
+
NzZiYTQ0NTAwNzQ4NjRmOGRiMmM2ZjJhZTY0NGYxN2FmOWExYTg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2IwMDY3Y2NiN2ZmNWNlZWE4M2Q2NTgyZjlmZTdjODYzNTlmMjBiYTJhMDhi
|
14
|
+
OWRjNjU5ZDU0Mzk4NjA2NWYzY2Y2ODU4M2M5N2QyMDI3ZGM0ZDQwNmMxNTJi
|
15
|
+
OGNhOThlZjRlN2I1OGUyMDM5NTUyYTAyNzYwMGY0MDYyMGM1MTg=
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'pathname'
|
3
|
+
require 'set'
|
4
|
+
require 'digest'
|
3
5
|
|
4
6
|
class Object
|
5
7
|
def a?
|
@@ -7,8 +9,23 @@ class Object
|
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
12
|
+
class Array
|
13
|
+
def to_set
|
14
|
+
Set.new self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
module FileUtils
|
11
|
-
$fudeopt = []
|
19
|
+
$fudeopt = [].to_set
|
20
|
+
@popts = {
|
21
|
+
:cp => [:T,:a,:v,:r].to_set,
|
22
|
+
:mv => [:T,:a,:v,:r].to_set,
|
23
|
+
:rm => [:v, :f, :r].to_set,
|
24
|
+
:touch => [:v].to_set,
|
25
|
+
:pwd => [].to_set,
|
26
|
+
:mkdir => [:v, :p].to_set,
|
27
|
+
:dsync => [:v, ].to_set,
|
28
|
+
}
|
12
29
|
|
13
30
|
class << self
|
14
31
|
def parse_cp_args src, dst, *opts
|
@@ -40,7 +57,7 @@ module FileUtils
|
|
40
57
|
opts_s = '-f '
|
41
58
|
|
42
59
|
[:T, :a, :v, :r].each do |opt|
|
43
|
-
opts_s << "-#{opt.to_s} " if
|
60
|
+
opts_s << "-#{opt.to_s} " if include?(opt) || $fudeopt.include?(opt)
|
44
61
|
end
|
45
62
|
|
46
63
|
opts_s
|
@@ -53,6 +70,8 @@ module FileUtils
|
|
53
70
|
end
|
54
71
|
|
55
72
|
def cp src, dst, *opts
|
73
|
+
opts = opts.to_set
|
74
|
+
|
56
75
|
src, dst, opts = parse_cp_args src, dst, *opts
|
57
76
|
|
58
77
|
opts << :r if src.a? ? src.inject(false) do |a,p| p.directory? | a end : src.directory?
|
@@ -60,7 +79,41 @@ module FileUtils
|
|
60
79
|
Kernel.system "cp #{opts.to_s}#{src.to_s} #{dst.to_s}"
|
61
80
|
end
|
62
81
|
|
82
|
+
def dsync src, dst, *opts
|
83
|
+
src, dst, opts = parse_cp_args src, dst, *opts
|
84
|
+
|
85
|
+
opts = opts.to_set
|
86
|
+
|
87
|
+
raise ArgumentError unless src.directory? && dst.directory?
|
88
|
+
|
89
|
+
Dir["#{dst.to_s}/**/{*,.*}"].each do |file|
|
90
|
+
file = Pathname.new file
|
91
|
+
next unless file.exist?
|
92
|
+
|
93
|
+
srcfile = src + file.relative_path_from(dst)
|
94
|
+
|
95
|
+
rm file, *(opts&@popts[:rm]) unless srcfile.exist?
|
96
|
+
end
|
97
|
+
|
98
|
+
Dir["#{src.to_s}/**/{*,.*}"].each do |file|
|
99
|
+
file = Pathname.new file
|
100
|
+
next if file.directory?
|
101
|
+
|
102
|
+
dstfile = dst + file.relative_path_from(src)
|
103
|
+
|
104
|
+
(mkdir dstfile.dirname, *((opts+[:p])&@popts[:mkdir]) or return false) unless dstfile.dirname.directory?
|
105
|
+
|
106
|
+
next if dstfile.file? && Digest::SHA256.file(file) == Digest::SHA256.file(dstfile)
|
107
|
+
|
108
|
+
cp file, dstfile, *(opts&@popts[:cp]) or return false
|
109
|
+
end
|
110
|
+
|
111
|
+
true
|
112
|
+
end
|
113
|
+
|
63
114
|
def mv src, dst, *opts
|
115
|
+
opts = opts.to_set
|
116
|
+
|
64
117
|
src, dst, opts = parse_cp_args src, dst, *opts
|
65
118
|
|
66
119
|
Kernel.system "mv #{opts.to_s}#{src.to_s} #{dst.to_s}"
|
@@ -89,7 +142,7 @@ module FileUtils
|
|
89
142
|
opts_s = ''
|
90
143
|
|
91
144
|
@flags.each do |opt|
|
92
|
-
opts_s << "-#{opt.to_s} " if
|
145
|
+
opts_s << "-#{opt.to_s} " if include?(opt) || $fudeopt.include?(opt)
|
93
146
|
end
|
94
147
|
|
95
148
|
opts_s
|
@@ -102,6 +155,8 @@ module FileUtils
|
|
102
155
|
end
|
103
156
|
|
104
157
|
def rm list, *opts
|
158
|
+
opts = opts.to_set
|
159
|
+
|
105
160
|
list, opts = parse_list_args list, *opts
|
106
161
|
opts.flags = [:v, :f, :r]
|
107
162
|
|
@@ -111,10 +166,12 @@ module FileUtils
|
|
111
166
|
end
|
112
167
|
|
113
168
|
def mkdir list, *opts
|
169
|
+
opts = opts.to_set
|
170
|
+
|
114
171
|
list, opts = parse_list_args list, *opts
|
115
|
-
opts.flags = [:v]
|
172
|
+
opts.flags = [:v, :p]
|
116
173
|
|
117
|
-
if opts.
|
174
|
+
if opts.include? :f
|
118
175
|
unless list.a?
|
119
176
|
return true if list.directory?
|
120
177
|
else
|
@@ -127,6 +184,8 @@ module FileUtils
|
|
127
184
|
end
|
128
185
|
|
129
186
|
def touch list, *opts
|
187
|
+
opts = opts.to_set
|
188
|
+
|
130
189
|
list, opts = parse_list_args list, *opts
|
131
190
|
opts.flags = [:v]
|
132
191
|
|