summaryrefslogtreecommitdiff
path: root/src/file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/file.rs')
-rw-r--r--src/file.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/file.rs b/src/file.rs
new file mode 100644
index 0000000..2e69cdd
--- /dev/null
+++ b/src/file.rs
@@ -0,0 +1,31 @@
+use std::{
+ fs::File,
+ path::{Path, PathBuf},
+};
+
+use happylock::ThreadKey;
+use uuid::Uuid;
+
+use crate::processes::process_id;
+
+fn root() -> &'static Path {
+ Path::new("~/.dozos")
+}
+
+fn path(root: &Path, program_id: Uuid, file_id: Uuid) -> PathBuf {
+ let mut builder = PathBuf::from(root);
+ builder.push(program_id.to_string());
+ builder.push(file_id.to_string());
+
+ builder
+}
+
+pub fn open(key: &mut ThreadKey, file_id: Uuid) -> std::io::Result<File> {
+ let path = path(root(), process_id(key), file_id);
+ File::options()
+ .read(true)
+ .write(true)
+ .create(true)
+ .truncate(false)
+ .open(path)
+}