Class: Microsandbox::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/microsandbox/fs.rb

Overview

Guest filesystem operations for a running sandbox. Obtain via Sandbox#fs. All paths are paths inside the guest VM.

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ FS

Returns a new instance of FS.



83
84
85
# File 'lib/microsandbox/fs.rb', line 83

def initialize(native)
  @native = native
end

Instance Method Details

#copy(src, dst) ⇒ nil

Copy a file within the guest.

Returns:

  • (nil)


135
136
137
138
# File 'lib/microsandbox/fs.rb', line 135

def copy(src, dst)
  @native.fs_copy(src.to_s, dst.to_s)
  nil
end

#copy_from_host(host_path, guest_path) ⇒ nil

Copy a file from the host into the guest.

Returns:

  • (nil)


160
161
162
163
# File 'lib/microsandbox/fs.rb', line 160

def copy_from_host(host_path, guest_path)
  @native.fs_copy_from_host(host_path.to_s, guest_path.to_s)
  nil
end

#copy_to_host(guest_path, host_path) ⇒ nil

Copy a file from the guest to the host.

Returns:

  • (nil)


167
168
169
170
# File 'lib/microsandbox/fs.rb', line 167

def copy_to_host(guest_path, host_path)
  @native.fs_copy_to_host(guest_path.to_s, host_path.to_s)
  nil
end

#exists?(path) ⇒ Boolean

Returns whether the path exists in the guest.

Returns:

  • (Boolean)

    whether the path exists in the guest



148
149
150
# File 'lib/microsandbox/fs.rb', line 148

def exists?(path)
  @native.fs_exists(path.to_s)
end

#list(path) ⇒ Array<FsEntry>

List the entries of a directory.

Returns:



108
109
110
# File 'lib/microsandbox/fs.rb', line 108

def list(path)
  @native.fs_list(path.to_s).map { |entry| FsEntry.new(entry) }
end

#mkdir(path) ⇒ nil

Create a directory (and any missing parents).

Returns:

  • (nil)


114
115
116
117
# File 'lib/microsandbox/fs.rb', line 114

def mkdir(path)
  @native.fs_mkdir(path.to_s)
  nil
end

#read(path) ⇒ String

Read a file as raw bytes (ASCII-8BIT).

Returns:

  • (String)


89
90
91
# File 'lib/microsandbox/fs.rb', line 89

def read(path)
  @native.fs_read(path.to_s)
end

#read_text(path) ⇒ String

Read a file as a UTF-8 string.

Returns:

  • (String)


95
96
97
# File 'lib/microsandbox/fs.rb', line 95

def read_text(path)
  @native.fs_read_text(path.to_s)
end

#remove(path) ⇒ nil

Remove a single file.

Returns:

  • (nil)


121
122
123
124
# File 'lib/microsandbox/fs.rb', line 121

def remove(path)
  @native.fs_remove(path.to_s)
  nil
end

#remove_dir(path) ⇒ nil

Remove a directory recursively.

Returns:

  • (nil)


128
129
130
131
# File 'lib/microsandbox/fs.rb', line 128

def remove_dir(path)
  @native.fs_remove_dir(path.to_s)
  nil
end

#rename(src, dst) ⇒ nil

Rename/move a file or directory within the guest.

Returns:

  • (nil)


142
143
144
145
# File 'lib/microsandbox/fs.rb', line 142

def rename(src, dst)
  @native.fs_rename(src.to_s, dst.to_s)
  nil
end

#stat(path) ⇒ FsMetadata

Stat a path.

Returns:



154
155
156
# File 'lib/microsandbox/fs.rb', line 154

def stat(path)
  FsMetadata.new(@native.fs_stat(path.to_s))
end

#write(path, data) ⇒ nil

Write data (a String) to a file, creating or truncating it.

Returns:

  • (nil)


101
102
103
104
# File 'lib/microsandbox/fs.rb', line 101

def write(path, data)
  @native.fs_write(path.to_s, data.to_s)
  nil
end