Module: VirtFS::ContextSwitchClassMethods

Included in:
VirtFS
Defined in:
lib/virtfs/context_switch_class_methods.rb

Instance Method Summary collapse

Instance Method Details

#contextObject



7
8
9
# File 'lib/virtfs/context_switch_class_methods.rb', line 7

def context
  context_manager.current.current_context
end

#context!Object



11
12
13
# File 'lib/virtfs/context_switch_class_methods.rb', line 11

def context!
  context_manager.current!.current_context
end

#context_managerObject



3
4
5
# File 'lib/virtfs/context_switch_class_methods.rb', line 3

def context_manager
  ContextManager
end

#cwd=(dir) ⇒ Object



27
28
29
# File 'lib/virtfs/context_switch_class_methods.rb', line 27

def cwd=(dir)
  context.restore_cwd_root(dir, nil)
end

#dir_chdir(dir) ⇒ Object



40
41
42
# File 'lib/virtfs/context_switch_class_methods.rb', line 40

def dir_chdir(dir)
  context.chdir(dir)
end

#dir_chroot(dir) ⇒ Object



36
37
38
# File 'lib/virtfs/context_switch_class_methods.rb', line 36

def dir_chroot(dir)
  context.chroot(dir)
end

#dir_getwdObject



44
45
46
# File 'lib/virtfs/context_switch_class_methods.rb', line 44

def dir_getwd
  context.getwd
end

Expand symbolic links in the path. This must be done here, because a symlink in one file system can point to a file in another filesystem.



60
61
62
# File 'lib/virtfs/context_switch_class_methods.rb', line 60

def expand_links(p, include_last = true)
  context.expand_links(p, include_last)
end

#fs_call(fs, path = nil, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Invoke block withing the given filesystem context

Parameters:

  • fs (VirtFS::FS)

    filesystem intstance through which to invoke block

  • path (String) (defaults to: nil)

    path to specify to block

Raises:



78
79
80
81
82
83
84
# File 'lib/virtfs/context_switch_class_methods.rb', line 78

def fs_call(fs, path = nil, &block)
  block.arity < 1 ? fs.instance_eval(&block) : fs.instance_exec(path, &block)
rescue NoMethodError => err
  STDOUT.puts err.to_s
  STDOUT.puts err.backtrace.join("\n")
  raise VirtFS::NotImplementedError.new(fs, err.name)
end

#fs_lookup_call(path, raise_full_path = false, include_last = true, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Invoke block using fully resolved filesystem path



91
92
93
94
# File 'lib/virtfs/context_switch_class_methods.rb', line 91

def fs_lookup_call(path, raise_full_path = false, include_last = true, &block)
  fs, p = path_lookup(path, raise_full_path, include_last)
  fs_call(fs, p, &block)
end

#mount(fs_instance, mount_point) ⇒ Object



15
16
17
# File 'lib/virtfs/context_switch_class_methods.rb', line 15

def mount(fs_instance, mount_point)
  context.mount(fs_instance, mount_point)
end

#mounted?(mount_point) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/virtfs/context_switch_class_methods.rb', line 23

def mounted?(mount_point)
  context.mounted?(mount_point)
end

#normalize_path(p, relative_to = nil) ⇒ Object



64
65
66
67
68
# File 'lib/virtfs/context_switch_class_methods.rb', line 64

def normalize_path(p, relative_to = nil)
  # When running on windows, File.expand_path will add a drive letter.
  # Remove it if it's there.
  VfsRealFile.expand_path(p, relative_to || context.getwd).sub(/^[a-zA-Z]:/, "") # XXX
end

#path_lookup(path, raise_full_path = false, include_last = true) ⇒ Object

Expand symbolic links and perform mount indirection look up.



51
52
53
# File 'lib/virtfs/context_switch_class_methods.rb', line 51

def path_lookup(path, raise_full_path = false, include_last = true)
  context.path_lookup(path, raise_full_path, include_last)
end

#rootObject



31
32
33
34
# File 'lib/virtfs/context_switch_class_methods.rb', line 31

def root
  _cwd, root = context.cwd_root
  root
end

#umount(mount_point) ⇒ Object



19
20
21
# File 'lib/virtfs/context_switch_class_methods.rb', line 19

def umount(mount_point)
  context.umount(mount_point)
end