class VirtFS::VFile
VirtFS
File representation - implements the core Ruby File methods, dispatching to underlying mounted VirtFS
filesystems
Attributes
Public Class Methods
@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
@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
@return [String] base name of the file
# File lib/virtfs/v_file.rb, line 113 def basename(*args) VfsRealFile.basename(*args) end
@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
@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
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
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
@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 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
@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
@return [String] containg file directory name
# File lib/virtfs/v_file.rb, line 173 def dirname(*args) VfsRealFile.dirname(*args) end
@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
@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
@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
@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
@return [String] containg file extension name
# File lib/virtfs/v_file.rb, line 200 def extname(*args) VfsRealFile.extname(*args) end
@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
@return [Array<String>] names of files matching given args
# File lib/virtfs/v_file.rb, line 210 def fnmatch(*args) VfsRealFile.fnmatch(*args) end
@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
@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
@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
@return [String] containing joined path components
# File lib/virtfs/v_file.rb, line 234 def join(*args) VfsRealFile.join(*args) end
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
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
Create a symbol link between files
@param oname [String] file to link to @param nname [String] symbolic link to create
# File lib/virtfs/v_file.rb, line 268 def link(oname, nname) fs1, p1 = VirtFS.path_lookup(oname) fs2, p2 = VirtFS.path_lookup(nname) raise SystemCallError, "Can't hard link between filesystems" unless fs1 == fs2 # TODO: check exception VirtFS.fs_call(fs1) { file_link(p1, p2) } end
@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
@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
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
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
@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
@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
@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
@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
@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
@return [String] name of file references by link
# File lib/virtfs/v_file.rb, line 311 def readlink(f) VirtFS.fs_lookup_call(f, false, false) { |p| file_readlink(p) } end
@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
@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 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
@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
@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
@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
@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
@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
@return [Array<String>] split file path
# File lib/virtfs/v_file.rb, line 365 def split(f) VfsRealFile.split(f) end
@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
@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
Create new symlink to file
@param oname [String] file to link to @param nname [String] symbollic link to create
# File lib/virtfs/v_file.rb, line 384 def symlink(oname, nname) # # oname is the path to the original file in the global FS namespace. # It is not modified and used as the link target. # VirtFS.fs_lookup_call(nname) { |p| file_symlink(oname, p) } end
@return [Boolean] indicating if file is symlink
# File lib/virtfs/v_file.rb, line 393 def symlink?(f) VirtFS.fs_lookup_call(f, false, false) { |p| file_symlink?(p) } end
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
@return [Integer] umake of file
# File lib/virtfs/v_file.rb, line 406 def umask(*args) VfsRealFile.umask(*args) end
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
@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
@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
@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
@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
# 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
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.
# File lib/virtfs/v_file.rb, line 27 def <<(obj) super self end
# File lib/virtfs/v_file.rb, line 32 def binmode super self end
# File lib/virtfs/v_file.rb, line 37 def each(*args) return self if (rv = super) == __getobj__ rv end
# File lib/virtfs/v_file.rb, line 42 def each_byte return self if (rv = super) == __getobj__ rv end
# File lib/virtfs/v_file.rb, line 47 def each_char return self if (rv = super) == __getobj__ rv end
# File lib/virtfs/v_file.rb, line 52 def each_codepoint return self if (rv = super) == __getobj__ rv end
# File lib/virtfs/v_file.rb, line 57 def flush return self if (rv = super) == __getobj__ rv end
@return [String] path which dir resides
# File lib/virtfs/v_file.rb, line 63 def path @open_path end
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
# File lib/virtfs/v_file.rb, line 83 def set_encoding(*args) super self end
# File lib/virtfs/v_file.rb, line 88 def to_io self end
Private Instance Methods
# File lib/virtfs/v_file.rb, line 92 def min_read_buf_sz=(val) __getobj__.send(:min_read_buf_sz=, val) rescue # ignore end