summaryrefslogtreecommitdiff
path: root/lib/fileutils.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-27 08:26:09 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-03-27 08:26:09 +0000
commit191b99c89d5843bdee2bccc9ee2d34bc2b5513f0 (patch)
tree825de62e8dce908c381b4113ba2d2d5aa64efc7a /lib/fileutils.rb
parentc92c0a593593da2eb1ff94d83d80f71e7ae5343c (diff)
Merge fileutils-1.2.0 from ruby/fileutils.
It includes the following updates: * https://github.com/ruby/fileutils/pull/26 * https://github.com/ruby/fileutils/pull/27 * https://github.com/ruby/fileutils/pull/29 * https://github.com/ruby/fileutils/pull/34 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/fileutils.rb')
-rw-r--r--lib/fileutils.rb28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index 4e1c00dec9..4c658ff62a 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -114,12 +114,14 @@ module FileUtils
#
# 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
#
@@ -1080,11 +1082,6 @@ module FileUtils
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
@@ -1093,6 +1090,7 @@ module FileUtils
when /\A\d+\z/
user.to_i
else
+ require 'etc'
Etc.getpwnam(user) ? Etc.getpwnam(user).uid : nil
end
end
@@ -1106,6 +1104,7 @@ module FileUtils
when /\A\d+\z/
group.to_i
else
+ require 'etc'
Etc.getgrnam(group) ? Etc.getgrnam(group).gid : nil
end
end
@@ -1275,8 +1274,15 @@ module FileUtils
def entries
opts = {}
opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
- Dir.children(path, opts)\
- .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