Class: Microsandbox::FS
- Inherits:
-
Object
- Object
- Microsandbox::FS
- 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
-
#copy(src, dst) ⇒ nil
Copy a file within the guest.
-
#copy_from_host(host_path, guest_path) ⇒ nil
Copy a file from the host into the guest.
-
#copy_to_host(guest_path, host_path) ⇒ nil
Copy a file from the guest to the host.
-
#exists?(path) ⇒ Boolean
Whether the path exists in the guest.
-
#initialize(native) ⇒ FS
constructor
A new instance of FS.
-
#list(path) ⇒ Array<FsEntry>
List the entries of a directory.
-
#mkdir(path) ⇒ nil
Create a directory (and any missing parents).
-
#read(path) ⇒ String
Read a file as raw bytes (ASCII-8BIT).
-
#read_text(path) ⇒ String
Read a file as a UTF-8 string.
-
#remove(path) ⇒ nil
Remove a single file.
-
#remove_dir(path) ⇒ nil
Remove a directory recursively.
-
#rename(src, dst) ⇒ nil
Rename/move a file or directory within the guest.
-
#stat(path) ⇒ FsMetadata
Stat a path.
-
#write(path, data) ⇒ nil
Write data (a String) to a file, creating or truncating it.
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.
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.
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.
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.
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.
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).
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).
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.
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.
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.
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.
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.
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.
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 |