MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / remove_file

Function remove_file

euralios_std/src/fs.rs:439–466  ·  view source on GitHub ↗

Delete a file

(path: P)

Source from the content-addressed store, hash-verified

437
438/// Delete a file
439pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<(), SyscallError> {
440 let path: &Path = path.as_ref();
441
442 // Get the directory containing the file
443 let parent = match path.parent() {
444 Some(parent) => parent,
445 None => { return Err(syscalls::SYSCALL_ERROR_PARAM); }
446 };
447
448 // Get the file part of the path
449 let file_name = match path.file_name() {
450 Some(name) => name,
451 None => { return Err(syscalls::SYSCALL_ERROR_PARAM); }
452 };
453
454 // Open the directory containing this file
455 let f = File::open(parent)?;
456
457 // Send a delete message
458 let bytes = file_name.bytes();
459 match f.rcall(message::DELETE,
460 (bytes.len() as u64).into(),
461 MemoryHandle::from_u8_slice(bytes).into()) {
462 Err((err, _)) => Err(err),
463 Ok((message::OK, _, _)) => Ok(()),
464 _ => Err(syscalls::SYSCALL_ERROR_PARAM)
465 }
466}
467
468pub fn create_dir<P: AsRef<Path>>(path: P) -> Result<(), SyscallError> {
469 let path: &Path = path.as_ref();

Callers 1

rmFunction · 0.85

Calls 7

parentMethod · 0.80
rcallMethod · 0.80
openFunction · 0.70
as_refMethod · 0.45
file_nameMethod · 0.45
bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected