Class: FileUtils::Entry_
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
StreamUtils_
|
|
Inherits: | Object |
Defined in: | lib/fileutils.rb |
Overview
internal use only
Constant Summary
-
DIRECTORY_TERM =
# File 'lib/fileutils.rb', line 1539"(?=/|\\z)"
-
SYSCASE =
# File 'lib/fileutils.rb', line 1543File::FNM_SYSCASE.nonzero? ? "-i" : ""
-
S_IF_DOOR =
# File 'lib/fileutils.rb', line 12670xD000
Class Method Summary
- .new(a, b = nil, deref = false) ⇒ Entry_ constructor
Instance Attribute Summary
- #blockdev? ⇒ Boolean readonly
- #chardev? ⇒ Boolean readonly
- #dereference? ⇒ Boolean readonly
- #directory? ⇒ Boolean readonly
- #door? ⇒ Boolean readonly
- #exist? ⇒ Boolean readonly
- #file? ⇒ Boolean readonly
- #pipe? ⇒ Boolean readonly
- #socket? ⇒ Boolean readonly
- #symlink? ⇒ Boolean readonly
- #check_have_lchmod? ⇒ Boolean readonly private
- #check_have_lchown? ⇒ Boolean readonly private
- #have_lchmod? ⇒ Boolean readonly private
- #have_lchown? ⇒ Boolean readonly private
Instance Method Summary
- #chmod(mode)
- #chown(uid, gid)
- #copy(dest)
- #copy_file(dest)
- #copy_metadata(path)
- #entries
- #inspect
- #link(dest)
- #lstat
- #lstat!
- #path
- #platform_support
- #postorder_traverse
- #prefix
- #preorder_traverse (also: #traverse)
- #rel
- #remove
- #remove_dir1
- #remove_file
- #stat
- #stat!
-
#traverse
Alias for #preorder_traverse.
- #wrap_traverse(pre, post)
- #descendant_directory?(descendant, ascendant) ⇒ Boolean private
- #join(dir, base) private
StreamUtils_
- Included
Constructor Details
.new(a, b = nil, deref = false) ⇒ Entry_
# File 'lib/fileutils.rb', line 1186
def initialize(a, b = nil, deref = false) @prefix = @rel = @path = nil if b @prefix = a @rel = b else @path = a end @deref = deref @stat = nil @lstat = nil end
Instance Attribute Details
#blockdev? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1252
def blockdev? s = lstat! s and s.blockdev? end
#chardev? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1247
def chardev? s = lstat! s and s.chardev? end
#check_have_lchmod? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/fileutils.rb', line 1506
def check_have_lchmod? return false unless File.respond_to?(:lchmod) File.lchmod 0 return true rescue NotImplementedError return false end
#check_have_lchown? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/fileutils.rb', line 1524
def check_have_lchown? return false unless File.respond_to?(:lchown) File.lchown nil, nil return true rescue NotImplementedError return false end
#dereference? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1219
def dereference? @deref end
#directory? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1237
def directory? s = lstat! s and s.directory? end
#door? ⇒ Boolean
(readonly)
[ GitHub ]
#exist? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1223
def exist? begin lstat true rescue Errno::ENOENT false end end
#file? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1232
def file? s = lstat! s and s.file? end
#have_lchmod? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/fileutils.rb', line 1498
def have_lchmod? # This is not MT-safe, but it does not matter. if $fileutils_rb_have_lchmod == nil $fileutils_rb_have_lchmod = check_have_lchmod? end $fileutils_rb_have_lchmod end
#have_lchown? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'lib/fileutils.rb', line 1516
def have_lchown? # This is not MT-safe, but it does not matter. if $fileutils_rb_have_lchown == nil $fileutils_rb_have_lchown = check_have_lchown? end $fileutils_rb_have_lchown end
#pipe? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1262
def pipe? s = lstat! s and s.pipe? end
#socket? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1257
def socket? s = lstat! s and s.socket? end
#symlink? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/fileutils.rb', line 1242
def symlink? s = lstat! s and s.symlink? end
Instance Method Details
#chmod(mode)
[ GitHub ]# File 'lib/fileutils.rb', line 1317
def chmod(mode) if symlink? File.lchmod mode, path() if have_lchmod? else File.chmod mode, path() end rescue Errno::EOPNOTSUPP end
#chown(uid, gid)
[ GitHub ]# File 'lib/fileutils.rb', line 1326
def chown(uid, gid) if symlink? File.lchown uid, gid, path() if have_lchown? else File.chown uid, gid, path() end end
#copy(dest)
[ GitHub ]# File 'lib/fileutils.rb', line 1350
def copy(dest) lstat case when file? copy_file dest when directory? if !File.exist?(dest) and descendant_directory?(dest, path) raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest] end begin Dir.mkdir dest rescue raise unless File.directory?(dest) end when symlink? File.symlink File.readlink(path()), dest when chardev? raise "cannot handle device file" unless File.respond_to?(:mknod) mknod dest, ?c, 0666, lstat().rdev when blockdev? raise "cannot handle device file" unless File.respond_to?(:mknod) mknod dest, ?b, 0666, lstat().rdev when socket? raise "cannot handle socket" unless File.respond_to?(:mknod) mknod dest, nil, lstat().mode, 0 when pipe? raise "cannot handle FIFO" unless File.respond_to?(:mkfifo) mkfifo dest, 0666 when door? raise "cannot handle door: #{path()}" else raise "unknown file type: #{path()}" end end
#copy_file(dest)
[ GitHub ]# File 'lib/fileutils.rb', line 1385
def copy_file(dest) File.open(path()) do |s| File.open(dest, 'wb', s.stat.mode) do |f| IO.copy_stream(s, f) end end end
#copy_metadata(path)
[ GitHub ]# File 'lib/fileutils.rb', line 1393
def (path) st = lstat() if !st.symlink? File.utime st.atime, st.mtime, path end mode = st.mode begin if st.symlink? begin File.lchown st.uid, st.gid, path rescue NotImplementedError end else File.chown st.uid, st.gid, path end rescue Errno::EPERM, Errno::EACCES # clear setuid/setgid mode &= 01777 end if st.symlink? begin File.lchmod mode, path rescue NotImplementedError, Errno::EOPNOTSUPP end else File.chmod mode, path end end
#descendant_directory?(descendant, ascendant) ⇒ Boolean
(private)
# File 'lib/fileutils.rb', line 1545
def descendant_directory?(descendant, ascendant) /\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant) end
#entries
[ GitHub ]#inspect
[ GitHub ]# File 'lib/fileutils.rb', line 1199
def inspect "\#<#{self.class} #{path()}>" end
#join(dir, base) (private)
[ GitHub ]#link(dest)
[ GitHub ]# File 'lib/fileutils.rb', line 1334
def link(dest) case when directory? if !File.exist?(dest) and descendant_directory?(dest, path) raise ArgumentError, "cannot link directory %s to itself %s" % [path, dest] end begin Dir.mkdir dest rescue raise unless File.directory?(dest) end else File.link path(), dest end end
#lstat
[ GitHub ]# File 'lib/fileutils.rb', line 1303
def lstat if dereference? @lstat ||= File.stat(path()) else @lstat ||= File.lstat(path()) end end
#lstat!
[ GitHub ]# File 'lib/fileutils.rb', line 1311
def lstat! lstat() rescue SystemCallError nil end
#path
[ GitHub ]# File 'lib/fileutils.rb', line 1203
def path if @path File.path(@path) else join(@prefix, @rel) end end
#platform_support
[ GitHub ]# File 'lib/fileutils.rb', line 1442
def platform_support return yield unless fu_windows? first_time_p = true begin yield rescue Errno::ENOENT raise rescue => err if first_time_p first_time_p = false begin File.chmod 0700, path() # Windows does not have symlink retry rescue SystemCallError end end raise err end end
#postorder_traverse
[ GitHub ]# File 'lib/fileutils.rb', line 1472
def postorder_traverse if directory? entries().each do |ent| ent.postorder_traverse do |e| yield e end end end ensure yield self end
#prefix
[ GitHub ]# File 'lib/fileutils.rb', line 1211
def prefix @prefix || @path end
#preorder_traverse Also known as: #traverse
[ GitHub ]# File 'lib/fileutils.rb', line 1462
def preorder_traverse stack = [self] while ent = stack.pop yield ent stack.concat ent.entries.reverse if ent.directory? end end
#rel
[ GitHub ]# File 'lib/fileutils.rb', line 1215
def rel @rel end
#remove
[ GitHub ]# File 'lib/fileutils.rb', line 1422
def remove if directory? remove_dir1 else remove_file end end
#remove_dir1
[ GitHub ]# File 'lib/fileutils.rb', line 1430
def remove_dir1 platform_support { Dir.rmdir path().chomp(?/) } end
#remove_file
[ GitHub ]# File 'lib/fileutils.rb', line 1436
def remove_file platform_support { File.unlink path } end
#stat
[ GitHub ]#stat!
[ GitHub ]#traverse
Alias for #preorder_traverse.
# File 'lib/fileutils.rb', line 1470
alias traverse preorder_traverse
#wrap_traverse(pre, post)
[ GitHub ]# File 'lib/fileutils.rb', line 1484
def wrap_traverse(pre, post) pre.call self if directory? entries.each do |ent| ent.wrap_traverse pre, post end end post.call self end