Class: RubySMB::Server::Share::Provider::VirtualDisk::VirtualMappedFile

Inherits:
VirtualPathname
  • Object
show all
Defined in:
lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb

Overview

A mapped file is one who is backed by an entry on disk. The path need not be present, but if it does exist, it must be a file.

Since:

  • 3.1.1

Constant Summary

Constants inherited from VirtualPathname

RubySMB::Server::Share::Provider::VirtualDisk::VirtualPathname::SEPARATOR

Instance Attribute Summary

Attributes inherited from VirtualPathname

#virtual_disk

Instance Method Summary collapse

Methods inherited from VirtualPathname

#<=>, #==, #absolute?, basename, #basename, #children, cleanpath, #cleanpath, #dirname, dirname, #entries, #extname, #join, #relative?, #split, #to_s

Constructor Details

#initialize(disk, path, mapped_path) ⇒ VirtualMappedFile

Returns a new instance of VirtualMappedFile.

Parameters:

  • disk (Hash)

    The mapping of paths to objects representing the virtual file system.

  • path (String)

    The path of this entry.

  • mapped_path (String, Pathname)

    The path on the local file system to map into the virtual file system.

Raises:

  • (ArgumentError)

Since:

  • 3.1.1



58
59
60
61
62
63
64
65
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 58

def initialize(disk, path, mapped_path)
  mapped_path = Pathname.new(File.expand_path(mapped_path)) if mapped_path.is_a?(String)
  raise ArgumentError.new('mapped_path must be absolute') unless mapped_path.absolute? # it needs to be absolute so it is independent of the cwd

  @virtual_disk = disk
  @path = path
  @mapped_path = mapped_path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubySMB::Server::Share::Provider::VirtualDisk::VirtualPathname

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)

Since:

  • 3.1.1



67
68
69
70
71
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 67

def exist?
  # filter out anything that's not a directory but allow the file to be missing, this prevents exposing
  # directories which could yield path confusion errors
  @mapped_path.exist? && @mapped_path.file?
end

#open(mode = 'r', &block) ⇒ Object

Since:

  • 3.1.1



77
78
79
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 77

def open(mode = 'r', &block)
  @mapped_path.open(mode, &block)
end

#statObject

Since:

  • 3.1.1



73
74
75
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 73

def stat
  @mapped_path.stat
end