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

Method write_file

atomic-core/src/output/filesystem/mod.rs:313–339  ·  view source on GitHub ↗

Open a file for writing, creating it if necessary.

(&self, path: &str, inode: Inode)

Source from the content-addressed store, hash-verified

311
312 /// Open a file for writing, creating it if necessary.
313 fn write_file(&self, path: &str, inode: Inode) -> Result<Self::Writer, Self::Error> {
314 let abs_path = self.resolve_path(path)?;
315
316 // Create parent directories
317 if let Some(parent) = abs_path.parent() {
318 if !parent.exists() {
319 fs::create_dir_all(parent)?;
320 }
321 }
322
323 // A kind transition from symlink to regular must unlink first;
324 // opening with truncate would otherwise overwrite the link target.
325 if fs::symlink_metadata(&abs_path)
326 .map(|metadata| metadata.file_type().is_symlink())
327 .unwrap_or(false)
328 {
329 fs::remove_file(&abs_path)?;
330 }
331
332 let file = OpenOptions::new()
333 .write(true)
334 .create(true)
335 .truncate(true)
336 .open(&abs_path)?;
337
338 Ok(FileWriter::new(file, abs_path, inode))
339 }
340}

Calls 7

parentMethod · 0.80
truncateMethod · 0.80
resolve_pathMethod · 0.45
existsMethod · 0.45
openMethod · 0.45
createMethod · 0.45
writeMethod · 0.45