MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / add_file

Method add_file

atomic-core/src/output/memory.rs:314–325  ·  view source on GitHub ↗

Add a file with the given contents. This is a convenience method for testing. Creates parent directories automatically. # Example ```rust use atomic_core::output::{Memory, WorkingCopyRead}; let wc = Memory::new(); wc.add_file("src/main.rs", b"fn main() {}"); let mut buf = Vec::new(); wc.read_file("src/main.rs", &mut buf).unwrap(); assert_eq!(buf, b"fn main() {}"); ```

(&self, path: &str, contents: &[u8])

Source from the content-addressed store, hash-verified

312 /// assert_eq!(buf, b"fn main() {}");
313 /// ```
314 pub fn add_file(&self, path: &str, contents: &[u8]) {
315 // Create parent directories
316 if let Some(parent) = path_parent(path) {
317 self.ensure_directories(&parent);
318 }
319
320 let inode = self.allocate_inode();
321 self.files.borrow_mut().insert(
322 path.to_string(),
323 MemoryFile::new_file(contents.to_vec(), inode),
324 );
325 }
326
327 /// Add a directory.
328 ///

Callers 15

test_memory_debugFunction · 0.45
test_memory_clearFunction · 0.45
test_add_fileFunction · 0.45
test_list_filesFunction · 0.45
test_get_inodeFunction · 0.45
test_file_metadataFunction · 0.45
test_read_fileFunction · 0.45
test_read_file_appendsFunction · 0.45
test_modified_timeFunction · 0.45
test_existsFunction · 0.45
test_is_directoryFunction · 0.45

Calls 4

path_parentFunction · 0.85
ensure_directoriesMethod · 0.80
allocate_inodeMethod · 0.80
insertMethod · 0.45

Tested by 15

test_memory_debugFunction · 0.36
test_memory_clearFunction · 0.36
test_add_fileFunction · 0.36
test_list_filesFunction · 0.36
test_get_inodeFunction · 0.36
test_file_metadataFunction · 0.36
test_read_fileFunction · 0.36
test_read_file_appendsFunction · 0.36
test_modified_timeFunction · 0.36
test_existsFunction · 0.36
test_is_directoryFunction · 0.36