posix-fileutils 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/posix-fileutils/fileutils.rb +131 -133
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGQxOWVmNGUwZGVmOTM4MWMxYmNiMmNmY2VkMGFhZGUxZTNkNWNiMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjRhY2UzOGFkY2U3MTUyZTc3YjQ1MTZlYTM5MTkwMjE0MDc1NWIzNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2UxNWMzZmIxNWY3MjlmOTFjYjgwNmE5ZjE0ZjdhZDkyY2RjZDQzOTNmM2Rk
|
10
|
+
OWU4YWZlYzMzZmRlNmViMmY0MDFhM2U0OTlhYzA2YzE1ZmM0NTNiODcyNzUy
|
11
|
+
MTcxMzQwOWMyMThlY2JhNTM4NWZkNTBlMGRiOGY5NTU3MGRkOWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YWIyYzRkMThjOGU1NTVhNTliYTkzNWY2MzZhODljNjZiZjZmNTZiNjk4OGIy
|
14
|
+
YmVlMjRkZDNjZDJmNzYwODBiZmY2NzRmZTIzNDFhNmE4YjVmYTg1NGMxZTJi
|
15
|
+
NTc2YzEzNjRkMDQ2OTlmYmUyNjRmZDIxNzMwNmQ0ZDVhMGU3YzM=
|
@@ -27,203 +27,201 @@ module FileUtils
|
|
27
27
|
:dsync => [:v, ].to_set,
|
28
28
|
}
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
raise ArgumentError unless !dst.a?
|
30
|
+
def parse_cp_args src, dst, *opts
|
31
|
+
raise ArgumentError unless !dst.a?
|
33
32
|
|
34
|
-
|
33
|
+
dst = Pathname.new dst.to_s unless dst.kind_of? Pathname
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
if src.a?
|
36
|
+
return true if src.count == 0
|
38
37
|
|
39
|
-
|
38
|
+
raise ArgumentError unless dst.directory?
|
40
39
|
|
41
|
-
|
40
|
+
src.map! do |elem| Pathname.new elem.to_s unless elem.kind_of? Pathname end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
42
|
+
class << src
|
43
|
+
def to_s
|
44
|
+
inject('') do |accu, elem| "#{accu}#{elem.to_s} " end.chomp ' '
|
47
45
|
end
|
48
|
-
else
|
49
|
-
src = Pathname.new src.to_s unless src.kind_of? Pathname
|
50
46
|
end
|
47
|
+
else
|
48
|
+
src = Pathname.new src.to_s unless src.kind_of? Pathname
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def to_s
|
57
|
-
opts_s = '-f '
|
51
|
+
class << opts
|
52
|
+
attr_accessor :src
|
53
|
+
attr_accessor :dst
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
55
|
+
def to_s
|
56
|
+
opts_s = '-f '
|
62
57
|
|
63
|
-
|
58
|
+
[:T, :a, :v, :r].each do |opt|
|
59
|
+
opts_s << "-#{opt.to_s} " if include?(opt) || $fudeopt.include?(opt)
|
64
60
|
end
|
65
|
-
end
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
[src, dst, opts]
|
62
|
+
opts_s
|
63
|
+
end
|
70
64
|
end
|
71
|
-
module_function :parse_cp_args
|
72
65
|
|
73
|
-
|
74
|
-
opts = opts.to_set
|
66
|
+
opts.src, opts.dst = src, dst
|
75
67
|
|
76
|
-
|
68
|
+
[src, dst, opts]
|
69
|
+
end
|
70
|
+
module_function :parse_cp_args
|
77
71
|
|
78
|
-
|
72
|
+
def cp src, dst, *opts
|
73
|
+
opts = opts.to_set
|
79
74
|
|
80
|
-
|
81
|
-
end
|
82
|
-
module_function :cp
|
75
|
+
src, dst, opts = parse_cp_args src, dst, *opts
|
83
76
|
|
84
|
-
|
85
|
-
src, dst, opts = parse_cp_args src, dst, *opts
|
77
|
+
opts << :r if src.a? ? src.inject(false) do |a,p| p.directory? | a end : src.directory?
|
86
78
|
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
Kernel.system "cp #{opts.to_s}#{src.to_s} #{dst.to_s}"
|
80
|
+
end
|
81
|
+
module_function :cp
|
90
82
|
|
91
|
-
|
92
|
-
|
93
|
-
next unless file.exist?
|
83
|
+
def dsync src, dst, *opts
|
84
|
+
src, dst, opts = parse_cp_args src, dst, *opts
|
94
85
|
|
95
|
-
|
86
|
+
opts = opts.to_set
|
87
|
+
|
88
|
+
raise ArgumentError unless src.directory? && dst.directory?
|
96
89
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
Dir["#{src.to_s}/**/{*,.*}"].each do |file|
|
101
|
-
file = Pathname.new file
|
102
|
-
next if file.directory?
|
90
|
+
Dir["#{dst.to_s}/**/{*,.*}"].each do |file|
|
91
|
+
file = Pathname.new file
|
92
|
+
next unless file.exist?
|
103
93
|
|
104
|
-
|
94
|
+
srcfile = src + file.relative_path_from(dst)
|
105
95
|
|
106
|
-
|
96
|
+
(rm file, *(opts&@popts[:rm]) or return false) unless srcfile.exist?
|
97
|
+
end
|
98
|
+
|
99
|
+
Dir["#{src.to_s}/**/{*,.*}"].each do |file|
|
100
|
+
file = Pathname.new file
|
101
|
+
next if file.directory?
|
107
102
|
|
108
|
-
|
103
|
+
dstfile = dst + file.relative_path_from(src)
|
109
104
|
|
110
|
-
|
111
|
-
end
|
105
|
+
(mkdir dstfile.dirname, *((opts+[:p])&@popts[:mkdir]) or return false) unless dstfile.dirname.directory?
|
112
106
|
|
113
|
-
|
107
|
+
next if dstfile.file? && Digest::SHA256.file(file) == Digest::SHA256.file(dstfile)
|
108
|
+
|
109
|
+
cp file, dstfile, *(opts&@popts[:cp]) or return false
|
114
110
|
end
|
115
|
-
module_function :dsync
|
116
111
|
|
117
|
-
|
118
|
-
|
112
|
+
true
|
113
|
+
end
|
114
|
+
module_function :dsync
|
115
|
+
|
116
|
+
def mv src, dst, *opts
|
117
|
+
opts = opts.to_set
|
119
118
|
|
120
|
-
|
119
|
+
src, dst, opts = parse_cp_args src, dst, *opts
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
Kernel.system "mv #{opts.to_s}#{src.to_s} #{dst.to_s}"
|
122
|
+
end
|
123
|
+
module_function :mv
|
125
124
|
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
def parse_list_args list, *opts
|
126
|
+
if list.a?
|
127
|
+
return true if list.count == 0
|
129
128
|
|
130
|
-
|
129
|
+
list.map! do |elem| Pathname.new elem.to_s unless elem.kind_of? Pathname end
|
131
130
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
131
|
+
class << list
|
132
|
+
def to_s
|
133
|
+
inject('') do |accu,elem| "#{accu}#{elem.to_s} " end.chomp ' '
|
136
134
|
end
|
137
|
-
else
|
138
|
-
list = Pathname.new list.to_s unless list.kind_of? Pathname
|
139
135
|
end
|
136
|
+
else
|
137
|
+
list = Pathname.new list.to_s unless list.kind_of? Pathname
|
138
|
+
end
|
140
139
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
def to_s
|
146
|
-
opts_s = ''
|
140
|
+
class << opts
|
141
|
+
attr_accessor :list
|
142
|
+
attr_accessor :flags
|
147
143
|
|
148
|
-
|
149
|
-
|
150
|
-
end
|
144
|
+
def to_s
|
145
|
+
opts_s = ''
|
151
146
|
|
152
|
-
|
147
|
+
@flags.each do |opt|
|
148
|
+
opts_s << "-#{opt.to_s} " if include?(opt) || $fudeopt.include?(opt)
|
153
149
|
end
|
150
|
+
|
151
|
+
opts_s
|
154
152
|
end
|
153
|
+
end
|
155
154
|
|
156
|
-
|
155
|
+
opts.list = list
|
157
156
|
|
158
|
-
|
159
|
-
|
160
|
-
|
157
|
+
[list, opts]
|
158
|
+
end
|
159
|
+
module_function :parse_list_args
|
161
160
|
|
162
|
-
|
163
|
-
|
161
|
+
def rm list, *opts
|
162
|
+
opts = opts.to_set
|
164
163
|
|
165
|
-
|
166
|
-
|
164
|
+
list, opts = parse_list_args list, *opts
|
165
|
+
opts.flags = [:v, :f, :r]
|
167
166
|
|
168
|
-
|
167
|
+
opts << :r if list.a? ? list.inject(false) do |a,p| p.directory? | a end : list.directory?
|
169
168
|
|
170
|
-
|
171
|
-
|
172
|
-
|
169
|
+
Kernel.system "rm #{opts.to_s}#{list.to_s}"
|
170
|
+
end
|
171
|
+
module_function :rm
|
173
172
|
|
174
|
-
|
175
|
-
|
173
|
+
def mkdir list, *opts
|
174
|
+
opts = opts.to_set
|
176
175
|
|
177
|
-
|
178
|
-
|
176
|
+
list, opts = parse_list_args list, *opts
|
177
|
+
opts.flags = [:v, :p]
|
179
178
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
179
|
+
if opts.include? :f
|
180
|
+
unless list.a?
|
181
|
+
return true if list.directory?
|
182
|
+
else
|
183
|
+
list.select! do |elem| !elem.directory? end
|
184
|
+
return true if list.empty?
|
187
185
|
end
|
188
|
-
|
189
|
-
Kernel.system "mkdir #{opts.to_s}#{list.to_s}"
|
190
186
|
end
|
191
|
-
module_function :mkdir
|
192
187
|
|
193
|
-
|
194
|
-
|
188
|
+
Kernel.system "mkdir #{opts.to_s}#{list.to_s}"
|
189
|
+
end
|
190
|
+
module_function :mkdir
|
195
191
|
|
196
|
-
|
197
|
-
|
192
|
+
def touch list, *opts
|
193
|
+
opts = opts.to_set
|
198
194
|
|
199
|
-
|
200
|
-
|
201
|
-
|
195
|
+
list, opts = parse_list_args list, *opts
|
196
|
+
opts.flags = [:v]
|
197
|
+
|
198
|
+
Kernel.system "touch #{opts.to_s}#{list.to_s}"
|
199
|
+
end
|
200
|
+
module_function :touch
|
202
201
|
|
203
|
-
|
202
|
+
alias_method :_cd, :cd
|
204
203
|
|
205
|
-
|
206
|
-
|
204
|
+
def cd list, *opts
|
205
|
+
opts = opts.to_set
|
207
206
|
|
208
|
-
|
209
|
-
|
207
|
+
list, opts = parse_list_args list, *opts
|
208
|
+
opts.flags = [:v]
|
210
209
|
|
211
|
-
|
210
|
+
raise ArgumentError if list.a?
|
212
211
|
|
213
|
-
|
212
|
+
return false unless list.directory?
|
214
213
|
|
215
|
-
|
214
|
+
_cd list.to_s, opts.include?(:v) ? {:verbose => true} : {:verbose => false}
|
216
215
|
|
217
|
-
|
218
|
-
|
219
|
-
|
216
|
+
true
|
217
|
+
end
|
218
|
+
module_function :cd
|
220
219
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
220
|
+
def pwd
|
221
|
+
Pathname.new(`pwd`.chomp)
|
222
|
+
end
|
223
|
+
module_function :pwd
|
225
224
|
|
226
|
-
end # class << self
|
227
225
|
end # module FileUtils
|
228
226
|
|
229
227
|
# vim: sw=2 sts=2 ts=8:
|