lib/fileutils.rb in fileutils-1.1.0 vs lib/fileutils.rb in fileutils-1.2.0
- old
+ new
@@ -1,6 +1,15 @@
# frozen_string_literal: true
+
+begin
+ require 'rbconfig'
+rescue LoadError
+ # for make mjit-headers
+end
+
+require "fileutils/version"
+
#
# = fileutils.rb
#
# Copyright (c) 2000-2007 Minero Aoki
#
@@ -54,11 +63,11 @@
# either one file or a list of files in that argument. See the method
# documentation for examples.
#
# There are some `low level' methods, which do not accept any option:
#
-# FileUtils.copy_entry(src, dest, preserve = false, dereference = false)
+# FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
# FileUtils.copy_file(src, dest, preserve = false, dereference = true)
# FileUtils.copy_stream(srcstream, deststream)
# FileUtils.remove_entry(path, force = false)
# FileUtils.remove_entry_secure(path, force = false)
# FileUtils.remove_file(path, force = false)
@@ -82,17 +91,12 @@
#
# This module has all methods of FileUtils module, but never changes
# files/directories. This equates to passing the <tt>:noop</tt> and
# <tt>:verbose</tt> flags to methods in FileUtils.
#
-
-require 'rbconfig'
-
module FileUtils
- VERSION = "1.1.0"
-
def self.private_module_function(name) #:nodoc:
module_function name
private_class_method name
end
@@ -108,16 +112,18 @@
module_function :getwd
#
# Changes the current directory to the directory +dir+.
#
- # If this method is called with block, resumes to the old
- # working directory after the block execution finished.
+ # If this method is called with block, resumes to the previous
+ # working directory after the block execution has finished.
#
- # FileUtils.cd('/', :verbose => true) # chdir and report it
+ # FileUtils.cd('/') # change directory
#
- # FileUtils.cd('/') do # chdir
+ # FileUtils.cd('/', :verbose => true) # change directory and report it
+ #
+ # FileUtils.cd('/') do # change directory
# # ... # do something
# end # return to original directory
#
def cd(dir, verbose: nil, &block) # :yield: dir
fu_output_message "cd #{dir}" if verbose
@@ -517,17 +523,16 @@
destent = Entry_.new(d, nil, true)
begin
if destent.exist?
if destent.directory?
raise Errno::EEXIST, d
- else
- destent.remove_file if rename_cannot_overwrite_file?
end
end
begin
File.rename s, d
- rescue Errno::EXDEV
+ rescue Errno::EXDEV,
+ Errno::EPERM # move from unencrypted to encrypted dir (ext4)
copy_entry s, d, true
if secure
remove_entry_secure s, force
else
remove_entry s, force
@@ -541,15 +546,10 @@
module_function :mv
alias move mv
module_function :move
- def rename_cannot_overwrite_file? #:nodoc:
- /emx/ =~ RbConfig::CONFIG['host_os']
- end
- private_module_function :rename_cannot_overwrite_file?
-
#
# Remove file(s) specified in +list+. This method cannot remove directories.
# All StandardErrors are ignored when the :force option is set.
#
# FileUtils.rm %w( junk.txt dust.txt )
@@ -696,11 +696,11 @@
return
end
f.chown euid, -1
f.chmod 0700
}
- rescue EISDIR # JRuby in non-native mode can't open files as dirs
+ rescue Errno::EISDIR # JRuby in non-native mode can't open files as dirs
File.lstat(dot_file).tap {|fstat|
unless fu_stat_identical_entry?(st, fstat)
# symlink (TOC-to-TOU attack?)
File.unlink fullpath
return
@@ -1080,23 +1080,19 @@
end
end
end
module_function :chown_R
- begin
- require 'etc'
- rescue LoadError # rescue LoadError for miniruby
- end
-
def fu_get_uid(user) #:nodoc:
return nil unless user
case user
when Integer
user
when /\A\d+\z/
user.to_i
else
+ require 'etc'
Etc.getpwnam(user) ? Etc.getpwnam(user).uid : nil
end
end
private_module_function :fu_get_uid
@@ -1106,10 +1102,11 @@
when Integer
group
when /\A\d+\z/
group.to_i
else
+ require 'etc'
Etc.getgrnam(group) ? Etc.getgrnam(group).gid : nil
end
end
private_module_function :fu_get_gid
@@ -1146,12 +1143,15 @@
private
module StreamUtils_
private
- def fu_windows?
- /mswin|mingw|bccwin|emx/ =~ RbConfig::CONFIG['host_os']
+ case (defined?(::RbConfig) ? ::RbConfig::CONFIG['host_os'] : ::RUBY_PLATFORM)
+ when /mswin|mingw/
+ def fu_windows?; true end
+ else
+ def fu_windows?; false end
end
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
IO.copy_stream(src, dest)
end
@@ -1272,12 +1272,18 @@
end
def entries
opts = {}
opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
- Dir.entries(path(), opts)\
- .reject {|n| n == '.' or n == '..' }\
- .map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
+
+ files = if Dir.respond_to?(:children)
+ Dir.children(path, opts)
+ else
+ Dir.entries(path(), opts)
+ .reject {|n| n == '.' or n == '..' }
+ end
+
+ files.map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
end
def stat
return @stat if @stat
if lstat() and lstat().symlink?