fileutils 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -1
- data/Rakefile +2 -0
- data/fileutils.gemspec +3 -3
- data/lib/fileutils.rb +117 -22
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0aee7f293ec6d29fa463553496d041a986ddfb407fe3ea8788da72a5e5be089
|
4
|
+
data.tar.gz: 2e1a5e8678e34ef6cb8caf57c474035052da6985746212040eeae58d6b06f094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98dc33148493bef27a911a73f78f825de57929ad8eb3e3e9c47c40dbadb139c74b044011f78129b651155e8c2478266af5713f4e491765a351270e2cdecc8db4
|
7
|
+
data.tar.gz: 6209a27261211f2f724d51fd9abc0a6729023d0c7354f982c641d1b37670f7550b9a23b675cb8e49ada611cbdc794ceb5f7aa517bf4c9b71ed58ed3dc150d528
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
data/fileutils.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
Gem::Specification.new do |s|
|
3
4
|
s.name = "fileutils"
|
4
|
-
s.version = '1.0
|
5
|
-
s.date = '2017-12-22'
|
5
|
+
s.version = '1.1.0'
|
6
6
|
s.summary = "Several file utility methods for copying, moving, removing, etc."
|
7
7
|
s.description = "Several file utility methods for copying, moving, removing, etc."
|
8
8
|
|
9
9
|
s.require_path = %w{lib}
|
10
10
|
s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "fileutils.gemspec", "lib/fileutils.rb"]
|
11
|
-
s.required_ruby_version = ">= 2.
|
11
|
+
s.required_ruby_version = ">= 2.3.0"
|
12
12
|
|
13
13
|
s.authors = ["Minero Aoki"]
|
14
14
|
s.email = [nil]
|
data/lib/fileutils.rb
CHANGED
@@ -85,9 +85,11 @@
|
|
85
85
|
# <tt>:verbose</tt> flags to methods in FileUtils.
|
86
86
|
#
|
87
87
|
|
88
|
+
require 'rbconfig'
|
89
|
+
|
88
90
|
module FileUtils
|
89
91
|
|
90
|
-
VERSION = "1.0
|
92
|
+
VERSION = "1.1.0"
|
91
93
|
|
92
94
|
def self.private_module_function(name) #:nodoc:
|
93
95
|
module_function name
|
@@ -119,8 +121,9 @@ module FileUtils
|
|
119
121
|
#
|
120
122
|
def cd(dir, verbose: nil, &block) # :yield: dir
|
121
123
|
fu_output_message "cd #{dir}" if verbose
|
122
|
-
Dir.chdir(dir, &block)
|
124
|
+
result = Dir.chdir(dir, &block)
|
123
125
|
fu_output_message 'cd -' if verbose and block
|
126
|
+
result
|
124
127
|
end
|
125
128
|
module_function :cd
|
126
129
|
|
@@ -295,6 +298,39 @@ module FileUtils
|
|
295
298
|
alias link ln
|
296
299
|
module_function :link
|
297
300
|
|
301
|
+
#
|
302
|
+
# :call-seq:
|
303
|
+
# FileUtils.cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false)
|
304
|
+
#
|
305
|
+
# Hard link +src+ to +dest+. If +src+ is a directory, this method links
|
306
|
+
# all its contents recursively. If +dest+ is a directory, links
|
307
|
+
# +src+ to +dest/src+.
|
308
|
+
#
|
309
|
+
# +src+ can be a list of files.
|
310
|
+
#
|
311
|
+
# # Installing the library "mylib" under the site_ruby directory.
|
312
|
+
# FileUtils.rm_r site_ruby + '/mylib', :force => true
|
313
|
+
# FileUtils.cp_lr 'lib/', site_ruby + '/mylib'
|
314
|
+
#
|
315
|
+
# # Examples of linking several files to target directory.
|
316
|
+
# FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail'
|
317
|
+
# FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
|
318
|
+
#
|
319
|
+
# # If you want to link all contents of a directory instead of the
|
320
|
+
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
|
321
|
+
# # use the following code.
|
322
|
+
# FileUtils.cp_lr 'src/.', 'dest' # cp_lr('src', 'dest') makes dest/src, but this doesn't.
|
323
|
+
#
|
324
|
+
def cp_lr(src, dest, noop: nil, verbose: nil,
|
325
|
+
dereference_root: true, remove_destination: false)
|
326
|
+
fu_output_message "cp -lr#{remove_destination ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if verbose
|
327
|
+
return if noop
|
328
|
+
fu_each_src_dest(src, dest) do |s, d|
|
329
|
+
link_entry s, d, dereference_root, remove_destination
|
330
|
+
end
|
331
|
+
end
|
332
|
+
module_function :cp_lr
|
333
|
+
|
298
334
|
#
|
299
335
|
# :call-seq:
|
300
336
|
# FileUtils.ln_s(target, link, force: nil, noop: nil, verbose: nil)
|
@@ -341,6 +377,26 @@ module FileUtils
|
|
341
377
|
end
|
342
378
|
module_function :ln_sf
|
343
379
|
|
380
|
+
#
|
381
|
+
# Hard links a file system entry +src+ to +dest+.
|
382
|
+
# If +src+ is a directory, this method links its contents recursively.
|
383
|
+
#
|
384
|
+
# Both of +src+ and +dest+ must be a path name.
|
385
|
+
# +src+ must exist, +dest+ must not exist.
|
386
|
+
#
|
387
|
+
# If +dereference_root+ is true, this method dereferences the tree root.
|
388
|
+
#
|
389
|
+
# If +remove_destination+ is true, this method removes each destination file before copy.
|
390
|
+
#
|
391
|
+
def link_entry(src, dest, dereference_root = false, remove_destination = false)
|
392
|
+
Entry_.new(src, nil, dereference_root).traverse do |ent|
|
393
|
+
destent = Entry_.new(dest, ent.rel, false)
|
394
|
+
File.unlink destent.path if remove_destination && File.file?(destent.path)
|
395
|
+
ent.link destent.path
|
396
|
+
end
|
397
|
+
end
|
398
|
+
module_function :link_entry
|
399
|
+
|
344
400
|
#
|
345
401
|
# Copies a file content +src+ to +dest+. If +dest+ is a directory,
|
346
402
|
# copies +src+ to +dest/src+.
|
@@ -488,7 +544,7 @@ module FileUtils
|
|
488
544
|
module_function :move
|
489
545
|
|
490
546
|
def rename_cannot_overwrite_file? #:nodoc:
|
491
|
-
/emx/ =~
|
547
|
+
/emx/ =~ RbConfig::CONFIG['host_os']
|
492
548
|
end
|
493
549
|
private_module_function :rename_cannot_overwrite_file?
|
494
550
|
|
@@ -603,8 +659,8 @@ module FileUtils
|
|
603
659
|
#
|
604
660
|
# For details of this security vulnerability, see Perl's case:
|
605
661
|
#
|
606
|
-
# *
|
607
|
-
# *
|
662
|
+
# * https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2005-0448
|
663
|
+
# * https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452
|
608
664
|
#
|
609
665
|
# For fileutils.rb, this vulnerability is reported in [ruby-dev:26100].
|
610
666
|
#
|
@@ -628,22 +684,38 @@ module FileUtils
|
|
628
684
|
unless parent_st.sticky?
|
629
685
|
raise ArgumentError, "parent directory is world writable, FileUtils#remove_entry_secure does not work; abort: #{path.inspect} (parent directory mode #{'%o' % parent_st.mode})"
|
630
686
|
end
|
687
|
+
|
631
688
|
# freeze tree root
|
632
689
|
euid = Process.euid
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
690
|
+
dot_file = fullpath + "/."
|
691
|
+
begin
|
692
|
+
File.open(dot_file) {|f|
|
693
|
+
unless fu_stat_identical_entry?(st, f.stat)
|
694
|
+
# symlink (TOC-to-TOU attack?)
|
695
|
+
File.unlink fullpath
|
696
|
+
return
|
697
|
+
end
|
698
|
+
f.chown euid, -1
|
699
|
+
f.chmod 0700
|
700
|
+
}
|
701
|
+
rescue EISDIR # JRuby in non-native mode can't open files as dirs
|
702
|
+
File.lstat(dot_file).tap {|fstat|
|
703
|
+
unless fu_stat_identical_entry?(st, fstat)
|
704
|
+
# symlink (TOC-to-TOU attack?)
|
705
|
+
File.unlink fullpath
|
706
|
+
return
|
707
|
+
end
|
708
|
+
File.chown euid, -1, dot_file
|
709
|
+
File.chmod 0700, dot_file
|
710
|
+
}
|
711
|
+
end
|
712
|
+
|
713
|
+
unless fu_stat_identical_entry?(st, File.lstat(fullpath))
|
714
|
+
# TOC-to-TOU attack?
|
715
|
+
File.unlink fullpath
|
716
|
+
return
|
717
|
+
end
|
718
|
+
|
647
719
|
# ---- tree root is frozen ----
|
648
720
|
root = Entry_.new(path)
|
649
721
|
root.preorder_traverse do |ent|
|
@@ -744,8 +816,15 @@ module FileUtils
|
|
744
816
|
#
|
745
817
|
def compare_stream(a, b)
|
746
818
|
bsize = fu_stream_blksize(a, b)
|
747
|
-
|
748
|
-
|
819
|
+
|
820
|
+
if RUBY_VERSION > "2.4"
|
821
|
+
sa = String.new(capacity: bsize)
|
822
|
+
sb = String.new(capacity: bsize)
|
823
|
+
else
|
824
|
+
sa = String.new
|
825
|
+
sb = String.new
|
826
|
+
end
|
827
|
+
|
749
828
|
begin
|
750
829
|
a.read(bsize, sa)
|
751
830
|
b.read(bsize, sb)
|
@@ -1070,7 +1149,7 @@ module FileUtils
|
|
1070
1149
|
private
|
1071
1150
|
|
1072
1151
|
def fu_windows?
|
1073
|
-
/mswin|mingw|bccwin|emx/ =~
|
1152
|
+
/mswin|mingw|bccwin|emx/ =~ RbConfig::CONFIG['host_os']
|
1074
1153
|
end
|
1075
1154
|
|
1076
1155
|
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
|
@@ -1252,6 +1331,22 @@ module FileUtils
|
|
1252
1331
|
end
|
1253
1332
|
end
|
1254
1333
|
|
1334
|
+
def link(dest)
|
1335
|
+
case
|
1336
|
+
when directory?
|
1337
|
+
if !File.exist?(dest) and descendant_directory?(dest, path)
|
1338
|
+
raise ArgumentError, "cannot link directory %s to itself %s" % [path, dest]
|
1339
|
+
end
|
1340
|
+
begin
|
1341
|
+
Dir.mkdir dest
|
1342
|
+
rescue
|
1343
|
+
raise unless File.directory?(dest)
|
1344
|
+
end
|
1345
|
+
else
|
1346
|
+
File.link path(), dest
|
1347
|
+
end
|
1348
|
+
end
|
1349
|
+
|
1255
1350
|
def copy(dest)
|
1256
1351
|
lstat
|
1257
1352
|
case
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fileutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minero Aoki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -54,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 2.
|
57
|
+
version: 2.3.0
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.7.
|
65
|
+
rubygems_version: 2.7.6
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Several file utility methods for copying, moving, removing, etc.
|