123456789_123456789_123456789_123456789_123456789_

Class: Bundler::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/bundler/vendor/fileutils/lib/fileutils.rb

Overview

internal use only

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(a, b = nil, deref = false) ⇒ Entry_

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1203

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1269

def blockdev?
  s = lstat!
  s and s.blockdev?
end

#chardev?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1264

def chardev?
  s = lstat!
  s and s.chardev?
end

#check_have_lchmod?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1533

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1551

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1236

def dereference?
  @deref
end

#directory?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1254

def directory?
  s = lstat!
  s and s.directory?
end

#door?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1286

def door?
  s = lstat!
  s and (s.mode & 0xF000 == S_IF_DOOR)
end

#exist?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1240

def exist?
  begin
    lstat
    true
  rescue Errno::ENOENT
    false
  end
end

#file?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1249

def file?
  s = lstat!
  s and s.file?
end

#have_lchmod?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1525

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1543

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1279

def pipe?
  s = lstat!
  s and s.pipe?
end

#socket?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1274

def socket?
  s = lstat!
  s and s.socket?
end

#symlink?Boolean (readonly)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1259

def symlink?
  s = lstat!
  s and s.symlink?
end

Instance Method Details

#chmod(mode)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1342

def chmod(mode)
  if symlink?
    File.lchmod mode, path() if have_lchmod?
  else
    File.chmod mode, path()
  end
end

#chown(uid, gid)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1350

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1374

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?, blockdev?
    raise "cannot handle device file"
  when socket?
    begin
      require 'socket'
    rescue LoadError
      raise "cannot handle socket"
    else
      raise "cannot handle socket" unless defined?(UNIXServer)
    end
    UNIXServer.new(dest).close
    File.chmod lstat().mode, dest
  when pipe?
    raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
    File.mkfifo dest, lstat().mode
  when door?
    raise "cannot handle door: #{path()}"
  else
    raise "unknown file type: #{path()}"
  end
end

#copy_file(dest)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1412

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1420

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
    end
  else
    File.chmod mode, path
  end
end

#descendant_directory?(descendant, ascendant) ⇒ Boolean (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1571

def descendant_directory?(descendant, ascendant)
  if File::FNM_SYSCASE.nonzero?
    File.expand_path(File.dirname(descendant)).casecmp(File.expand_path(ascendant)) == 0
  else
    File.expand_path(File.dirname(descendant)) == File.expand_path(ascendant)
  end
end

#entries

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1291

def entries
  opts = {}
  opts[:encoding] = ::Encoding::UTF_8 if fu_windows?

  files = if Dir.respond_to?(:children)
    Dir.children(path, **opts)
  else
    Dir.entries(path(), **opts)
       .reject {|n| n == '.' or n == '..' }
  end

  untaint = RUBY_VERSION < '2.7'
  files.map {|n| Entry_.new(prefix(), join(rel(), untaint ? n.untaint : n)) }
end

#inspect

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1216

def inspect
  "\#<#{self.class} #{path()}>"
end

#join(dir, base) (private)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1559

def join(dir, base)
  return File.path(dir) if not base or base == '.'
  return File.path(base) if not dir or dir == '.'
  File.join(dir, base)
end

#lstat

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1328

def lstat
  if dereference?
    @lstat ||= File.stat(path())
  else
    @lstat ||= File.lstat(path())
  end
end

#lstat!

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1336

def lstat!
  lstat()
rescue SystemCallError
  nil
end

#path

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1220

def path
  if @path
    File.path(@path)
  else
    join(@prefix, @rel)
  end
end

#platform_support

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1469

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1499

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1228

def prefix
  @prefix || @path
end

#preorder_traverse Also known as: #traverse

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1489

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/bundler/vendor/fileutils/lib/fileutils.rb', line 1232

def rel
  @rel
end

#remove

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1449

def remove
  if directory?
    remove_dir1
  else
    remove_file
  end
end

#remove_dir1

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1457

def remove_dir1
  platform_support {
    Dir.rmdir path().chomp(?/)
  }
end

#remove_file

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1463

def remove_file
  platform_support {
    File.unlink path
  }
end

#stat

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1306

def stat
  return @stat if @stat
  if lstat() and lstat().symlink?
    @stat = File.stat(path())
  else
    @stat = lstat()
  end
  @stat
end

#stat!

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1316

def stat!
  return @stat if @stat
  if lstat! and lstat!.symlink?
    @stat = File.stat(path())
  else
    @stat = lstat!
  end
  @stat
rescue SystemCallError
  nil
end

#traverse

Alias for #preorder_traverse.

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1497

alias traverse preorder_traverse

#wrap_traverse(pre, post)

[ GitHub ]

  
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1511

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