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])
| 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 | /// |