class VirtFS::VFile

VirtFS File representation - implements the core Ruby File methods, dispatching to underlying mounted VirtFS filesystems

Attributes

fs_mod_obj[RW]

Public Class Methods

absolute_path(f, dirstring = nil) click to toggle source

@return absolute path of file (across mounted filesystems)

# File lib/virtfs/v_file.rb, line 102
def absolute_path(f, dirstring = nil)
  dir = dirstring || VirtFS.dir_getwd
  VfsRealFile.absolute_path(f, dir)
end
atime(f) click to toggle source

@return [Time] access time of the file

# File lib/virtfs/v_file.rb, line 108
def atime(f)
  VirtFS.fs_lookup_call(f) { |p| file_atime(p) }
end
basename(*args) click to toggle source

@return [String] base name of the file

# File lib/virtfs/v_file.rb, line 113
def basename(*args)
  VfsRealFile.basename(*args)
end
blockdev?(f) click to toggle source

@return [Boolean] indicating if file is a block device

# File lib/virtfs/v_file.rb, line 118
def blockdev?(f)
  VirtFS.fs_lookup_call(f) { |p| file_blockdev?(p) }
end
chardev?(f) click to toggle source

@return [Boolean] indicating if file is a char device

# File lib/virtfs/v_file.rb, line 123
def chardev?(f)
  VirtFS.fs_lookup_call(f) { |p| file_chardev?(p) }
end
chmod(permission, *files) click to toggle source

Change File ACLs

@param permission [Integer] new acl to assign to file(s)

# File lib/virtfs/v_file.rb, line 130
def chmod(permission, *files)
  nfp = 0
  files.each do |f|
    nfp += VirtFS.fs_lookup_call(f) { |p| file_chmod(permission, p) }
  end
  nfp
end
chown(owner, group, *files) click to toggle source

Change ownership / group ownership of file

@param owner [Integer,String] new owner of the file(s) @param group [Integer,String] new group owner of the file(s)

# File lib/virtfs/v_file.rb, line 142
def chown(owner, group, *files)
  owner = owner.to_int
  group = group.to_int
  nfp = 0
  files.each do |f|
    nfp += VirtFS.fs_lookup_call(f) { |p| file_chown(owner, group, p) }
  end
  nfp
end
ctime(f) click to toggle source

@return ]Time] change time of time

# File lib/virtfs/v_file.rb, line 153
def ctime(f)
  VirtFS.fs_lookup_call(f) { |p| file_ctime(p) }
end
delete(*files) click to toggle source

Delete specified files

# File lib/virtfs/v_file.rb, line 158
def delete(*files)
  nfp = 0
  files.each do |f|
    nfp += VirtFS.fs_lookup_call(f, false, false) { |p| file_delete(p) }
  end
  nfp
end
Also aliased as: unlink
directory?(f) click to toggle source

@return [Boolean] indiciating if file is a directory

# File lib/virtfs/v_file.rb, line 168
def directory?(f)
  VirtFS.fs_lookup_call(f) { |p| file_directory?(p) }
end
dirname(*args) click to toggle source

@return [String] containg file directory name

# File lib/virtfs/v_file.rb, line 173
def dirname(*args)
  VfsRealFile.dirname(*args)
end
executable?(f) click to toggle source

@return [Boolean] indiciating if file is executable

# File lib/virtfs/v_file.rb, line 178
def executable?(f)
  VirtFS.fs_lookup_call(f) { |p| file_executable?(p) }
end
executable_real?(f) click to toggle source

@return [Boolean] indiciating if file is executable and real

# File lib/virtfs/v_file.rb, line 183
def executable_real?(f)
  VirtFS.fs_lookup_call(f) { |p| file_executable_real?(p) }
end
exist?(f) click to toggle source

@return [Boolean] indiciating if file exists

# File lib/virtfs/v_file.rb, line 188
def exist?(f)
  VirtFS.fs_lookup_call(f) { |p| file_exist?(p) }
end
Also aliased as: exists?
exists?(f)
Alias for: exist?
expand_path(f, dirstring = nil) click to toggle source

@return [String] full expanded path to file

# File lib/virtfs/v_file.rb, line 194
def expand_path(f, dirstring = nil)
  dir = dirstring || VirtFS.dir_getwd
  VfsRealFile.expand_path(f, dir)
end
extname(*args) click to toggle source

@return [String] containg file extension name

# File lib/virtfs/v_file.rb, line 200
def extname(*args)
  VfsRealFile.extname(*args)
end
file?(f) click to toggle source

@return [Boolean] indiciating if file is a regular file

# File lib/virtfs/v_file.rb, line 205
def file?(f)
  VirtFS.fs_lookup_call(f) { |p| file_file?(p) }
end
fnmatch(*args) click to toggle source

@return [Array<String>] names of files matching given args

# File lib/virtfs/v_file.rb, line 210
def fnmatch(*args)
  VfsRealFile.fnmatch(*args)
end
Also aliased as: fnmatch?
fnmatch?(*args)
Alias for: fnmatch
ftype(f) click to toggle source

@return type of file specified

# File lib/virtfs/v_file.rb, line 216
def ftype(f)
  VirtFS.fs_lookup_call(f) { |p| file_ftype(p) }
end
grpowned?(f) click to toggle source

@return [Boolean] indicating if file is group owned

# File lib/virtfs/v_file.rb, line 221
def grpowned?(f)
  VirtFS.fs_lookup_call(f) { |p| file_grpowned?(p) }
end
identical?(fname1, fname2) click to toggle source

@return [Boolean] indicating if files are identical

# File lib/virtfs/v_file.rb, line 226
def identical?(fname1, fname2)
  fs1, p1 = VirtFS.path_lookup(fname1)
  fs2, p2 = VirtFS.path_lookup(fname2)
  return false unless fs1 == fs2
  VirtFS.fs_call(fs1) { file_identical?(p1, p2) }
end
join(*args) click to toggle source

@return [String] containing joined path components

# File lib/virtfs/v_file.rb, line 234
def join(*args)
  VfsRealFile.join(*args)
end
lchmod(permission, *files) click to toggle source

Invoke a 'lchmod' on the given files

@param permission [Integer] new permission to assign to file(s)

# File lib/virtfs/v_file.rb, line 242
def lchmod(permission, *files)
  nfp = 0
  files.each do |f|
    nfp += VirtFS.fs_lookup_call(f) { |p| file_lchmod(permission, p) }
  end
  nfp
end
lchown(owner, group, *files) click to toggle source

Invoke a 'lchown' on the given files

@param owner [String] new owner to assign to file(s) @param group [String] new group to assign to file(s)

# File lib/virtfs/v_file.rb, line 255
def lchown(owner, group, *files)
  nfp = 0
  files.each do |f|
    nfp += VirtFS.fs_lookup_call(f, false, false) { |p| file_lchown(owner, group, p) }
  end
  nfp
end
lstat(f) click to toggle source

@return [Stat] file stat for specified file

# File lib/virtfs/v_file.rb, line 276
def lstat(f)
  VirtFS.fs_lookup_call(f, false, false) { |p| file_lstat(p) }
end
mtime(f) click to toggle source

@return [Time] modification time of the specified file

# File lib/virtfs/v_file.rb, line 281
def mtime(f)
  VirtFS.fs_lookup_call(f) { |p| file_mtime(p) }
end
new(file_obj, path) click to toggle source

VFile initializer

@param file_obj [VirtFS::FS::File] handle to filesystem specific file obj @param path [String] path at which the file resides

# File lib/virtfs/v_file.rb, line 17
def initialize(file_obj, path)
  @open_path = path
  __setobj__(file_obj)
end
new(file_id, *args) click to toggle source

Instantiate new file instance.

@param file_id [String] file identifier (usually path) @param args args to forward to file initializer

# File lib/virtfs/v_file.rb, line 456
def new(file_id, *args) # rubocop:disable AbcSize
  if file_id.respond_to?(:to_int)
    fs_obj = VfsRealIO.new(file_id, *args)
  else
    parsed_args = FileModesAndOptions.new(*args)
    fs, p = VirtFS.path_lookup(file_id, false, false)
    fs_obj = VirtFS.fs_call(fs) { file_new(p, parsed_args, file_id, VDir.getwd) }
  end

  obj = allocate
  if fs.thin_interface?
    obj.send(:initialize, ThinFileDelegator.new(fs_obj, file_id, p, parsed_args), file_id)
  else
    obj.send(:initialize, fs_obj, file_id)
  end

  # fs_mod_obj always points to the fs module's file object
  # for use by fs-specific extension modules
  obj.fs_mod_obj = fs_obj
  obj.extend(fs_obj.extension_module) if fs_obj.respond_to?(:extension_module) # fs-specific extension module
  obj
end
owned?(f) click to toggle source

@return [Boolean] indicating if file is owned

# File lib/virtfs/v_file.rb, line 286
def owned?(f)
  VirtFS.fs_lookup_call(f) { |p| file_owned?(p) }
end
path(obj) click to toggle source

@return path to specified file object

# File lib/virtfs/v_file.rb, line 291
def path(obj)
  VfsRealFile.path(obj) # will check obj.to_path
end
pipe?(f) click to toggle source

@return [Boolean] indicating if file is pipe

# File lib/virtfs/v_file.rb, line 296
def pipe?(f)
  VirtFS.fs_lookup_call(f) { |p| file_pipe?(p) }
end
readable?(f) click to toggle source

@return [Boolean] indicating if file is readable

# File lib/virtfs/v_file.rb, line 301
def readable?(f)
  VirtFS.fs_lookup_call(f) { |p| file_readable?(p) }
end
readable_real?(f) click to toggle source

@return [Boolean] indicating if file is real and readable

# File lib/virtfs/v_file.rb, line 306
def readable_real?(f)
  VirtFS.fs_lookup_call(f) { |p| file_readable_real?(p) }
end
realdirpath(path, relative_to = nil) click to toggle source

@return [String] real directory containing file

# File lib/virtfs/v_file.rb, line 316
def realdirpath(path, relative_to = nil) # ???
  VirtFS.expand_links(VirtFS.normalize_path(path, relative_to))
end
realpath(path, relative_to = nil) click to toggle source

@return [String] real path of the file

# File lib/virtfs/v_file.rb, line 321
def realpath(path, relative_to = nil) # ???
  VirtFS.expand_links(VirtFS.normalize_path(path, relative_to))
end
rename(oname, nname) click to toggle source

Rename file

@param oname [String] file to rename @param nname [String] new name to assign to file

# File lib/virtfs/v_file.rb, line 330
def rename(oname, nname)
  fs1, p1 = VirtFS.path_lookup(oname)
  fs2, p2 = VirtFS.path_lookup(nname)
  raise SystemCallError, "Can't rename between filesystems" unless fs1 == fs2 # TODO: check exception
  VirtFS.fs_call(fs1) { file_rename(p1, p2) }
end
setgid?(f) click to toggle source

@return [Boolean] indicating if file GID is set

# File lib/virtfs/v_file.rb, line 338
def setgid?(f)
  VirtFS.fs_lookup_call(f) { |p| file_setgid?(p) }
end
setuid?(f) click to toggle source

@return [Boolean] indicating if file UID is set

# File lib/virtfs/v_file.rb, line 343
def setuid?(f)
  VirtFS.fs_lookup_call(f) { |p| file_setuid?(p) }
end
size(f) click to toggle source

@return [Integer] size of the file in bytes

# File lib/virtfs/v_file.rb, line 348
def size(f)
  VirtFS.fs_lookup_call(f) { |p| file_size(p) }
end
size?(f) click to toggle source

@return [Integer,nil] same as size but return nil if empty

# File lib/virtfs/v_file.rb, line 353
def size?(f)
  sz = size(f)
  return nil if sz == 0
  sz
end
socket?(f) click to toggle source

@return [Boolean] indicating if file is a socket

# File lib/virtfs/v_file.rb, line 360
def socket?(f)
  VirtFS.fs_lookup_call(f) { |p| file_socket?(p) }
end
split(f) click to toggle source

@return [Array<String>] split file path

# File lib/virtfs/v_file.rb, line 365
def split(f)
  VfsRealFile.split(f)
end
stat(f) click to toggle source

@return [Stat] file stat correspond to file

# File lib/virtfs/v_file.rb, line 370
def stat(f)
  VirtFS.fs_lookup_call(f) { |p| file_stat(p) }
end
sticky?(f) click to toggle source

@return [Boolean] indicating if file is sticky

# File lib/virtfs/v_file.rb, line 375
def sticky?(f)
  VirtFS.fs_lookup_call(f) { |p| file_sticky?(p) }
end
truncate(f, len) click to toggle source

Truncate file to the specified len

@param f [String] file to truncate @param len [Integer] length to truncate file to (in bytes)

# File lib/virtfs/v_file.rb, line 401
def truncate(f, len)
  VirtFS.fs_lookup_call(f) { |p| file_truncate(p, len) }
end
umask(*args) click to toggle source

@return [Integer] umake of file

# File lib/virtfs/v_file.rb, line 406
def umask(*args)
  VfsRealFile.umask(*args)
end
utime(atime, mtime, *files) click to toggle source

Update file time

@param atime [Time] new access time to assign to file(s) @param mtime [Time] new modification time to assign to file(s)

# File lib/virtfs/v_file.rb, line 414
def utime(atime, mtime, *files)
  nfp = 0
  files.each do |f|
    nfp += VirtFS.fs_lookup_call(f) { |p| file_utime(atime, mtime, p) }
  end
  nfp
end
world_readable?(f) click to toggle source

@return [Boolean] indicating if file is world readable

# File lib/virtfs/v_file.rb, line 423
def world_readable?(f)
  VirtFS.fs_lookup_call(f) { |p| file_world_readable?(p) }
end
world_writable?(f) click to toggle source

@return [Boolean] indicating if file is world writable

# File lib/virtfs/v_file.rb, line 428
def world_writable?(f)
  VirtFS.fs_lookup_call(f) { |p| file_world_writable?(p) }
end
writable?(f) click to toggle source

@return [Boolean] indicating if file is writable

# File lib/virtfs/v_file.rb, line 433
def writable?(f)
  VirtFS.fs_lookup_call(f) { |p| file_writable?(p) }
end
writable_real?(f) click to toggle source

@return [Boolean] indicating if file is writable and real

# File lib/virtfs/v_file.rb, line 438
def writable_real?(f)
  VirtFS.fs_lookup_call(f) { |p| file_writable_real?(p) }
end
zero?(f) click to toggle source
# File lib/virtfs/v_file.rb, line 442
def zero?(f)
  fs, p = VirtFS.path_lookup(f)
  begin
    VirtFS.fs_call(fs) { file_chardev?(p) }
    return fs.file_size(p) == 0
  rescue Errno::ENOENT
    return false
  end
end

Public Instance Methods

<<(obj) click to toggle source

Some methods need to return the File object. Methods in the delegator object can't do that, so we intercept them and do it here.

Calls superclass method
# File lib/virtfs/v_file.rb, line 27
def <<(obj)
  super
  self
end
binmode() click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 32
def binmode
  super
  self
end
each(*args) click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 37
def each(*args)
  return self if (rv = super) == __getobj__
  rv
end
each_byte() click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 42
def each_byte
  return self if (rv = super) == __getobj__
  rv
end
each_char() click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 47
def each_char
  return self if (rv = super) == __getobj__
  rv
end
each_codepoint() click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 52
def each_codepoint
  return self if (rv = super) == __getobj__
  rv
end
flush() click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 57
def flush
  return self if (rv = super) == __getobj__
  rv
end
path() click to toggle source

@return [String] path which dir resides

# File lib/virtfs/v_file.rb, line 63
def path
  @open_path
end
Also aliased as: to_path
reopen(*args) click to toggle source

Reopens file with the given args

# File lib/virtfs/v_file.rb, line 69
def reopen(*args)
  new_path = nil
  if !args[0].respond_to?(:to_str) && args[0].respond_to?(:__getobj__)
    # Given an IO object.
    to_obj = args[0]
    args = [to_obj.__getobj__]
    new_path = to_obj.path
  end
  new_obj = __getobj__.reopen(*args)
  __setobj__(new_obj)
  @open_path = new_path || new_obj.path
  self
end
set_encoding(*args) click to toggle source
Calls superclass method
# File lib/virtfs/v_file.rb, line 83
def set_encoding(*args)
  super
  self
end
to_io() click to toggle source
# File lib/virtfs/v_file.rb, line 88
def to_io
  self
end
to_path()
Alias for: path

Private Instance Methods

min_read_buf_sz=(val) click to toggle source
# File lib/virtfs/v_file.rb, line 92
def min_read_buf_sz=(val)
  __getobj__.send(:min_read_buf_sz=, val)
rescue
  # ignore
end