summaryrefslogtreecommitdiff
path: root/src/fs.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-26 17:54:22 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-29 00:22:39 -0400
commit4d386e9e1c79d557cae6af58e6df85eb470c1e0c (patch)
tree2a5bda6620b2d68ea5f06e4c49c9b9a3ad4c76f2 /src/fs.rs
parent1f093c12f84d269cb68370262d68ff6d515aef2e (diff)
Implement CodeCache
Diffstat (limited to 'src/fs.rs')
-rw-r--r--src/fs.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/fs.rs b/src/fs.rs
new file mode 100644
index 000000000..4ec9611ae
--- /dev/null
+++ b/src/fs.rs
@@ -0,0 +1,25 @@
+use std;
+use std::fs::File;
+use std::io::Read;
+use std::path::Path;
+
+#[allow(dead_code)]
+pub fn read_file_sync(path: &Path) -> std::io::Result<String> {
+ File::open(path).and_then(|mut f| {
+ let mut contents = String::new();
+ f.read_to_string(&mut contents)?;
+ Ok(contents)
+ })
+}
+
+pub fn mkdir(path: &Path) -> std::io::Result<()> {
+ debug!("mkdir -p {}", path.display());
+ assert!(path.has_root(), "non-has_root not yet implemented");
+ std::fs::create_dir_all(path).or_else(|err| {
+ if err.kind() == std::io::ErrorKind::AlreadyExists {
+ Ok(())
+ } else {
+ Err(err)
+ }
+ })
+}