diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-03-25 12:46:49 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-03-25 12:48:49 +1300 |
commit | ab84ad75629b0a4124221023ca91411d2cd62a32 (patch) | |
tree | 0c333f06bec5270084aaec71cf173c798420207b /src/devices/file_device/operations.rs | |
parent | 07ae3438917fd854a46924a410f6890cd0651f1b (diff) | |
download | bedrock-pc-ab84ad75629b0a4124221023ca91411d2cd62a32.zip |
Restructure program
This commit also includes changes to devices according to the latest
devices specification, in particular the math and system devices.
Diffstat (limited to 'src/devices/file_device/operations.rs')
-rw-r--r-- | src/devices/file_device/operations.rs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/devices/file_device/operations.rs b/src/devices/file_device/operations.rs deleted file mode 100644 index 3a3f81b..0000000 --- a/src/devices/file_device/operations.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::io::ErrorKind; -use std::path::Path; - - -/// Create a new file if it doesn't already exist, returning true if successful. -pub fn create_file(destination: &Path) -> bool { - if entry_exists(destination) { - false - } else { - if let Some(parent_path) = destination.parent() { - let _ = std::fs::create_dir_all(parent_path); - } - std::fs::OpenOptions::new().write(true).create_new(true) - .open(destination).is_ok() - } -} - -/// Move an entry from one location to another, returning true if successful. -pub fn move_entry(source: &Path, destination: &Path) -> bool { - if !entry_exists(source) || entry_exists(destination) { - return false; - } - std::fs::rename(source, destination).is_ok() -} - -/// Delete an entry, returning true if successful. -pub fn delete_entry(source: &Path) -> bool { - match std::fs::remove_file(source) { - Ok(_) => true, - Err(e) => match e.kind() { - ErrorKind::NotFound => true, - ErrorKind::IsADirectory => match std::fs::remove_dir_all(source) { - Ok(_) => true, - Err(e) => match e.kind() { - ErrorKind::NotFound => true, - _ => false, - } - } - _ => false, - } - } -} - -/// Returns true if an entry already exists at the given path. -fn entry_exists(source: &Path) -> bool { - std::fs::metadata(source).is_ok() -} |