summaryrefslogtreecommitdiff
path: root/server/src/fs_utils.rs
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-01-26 21:58:42 +0100
committerJoel Klinghed <the_jk@spawned.biz>2025-01-26 21:58:42 +0100
commit9e80b8cd1e44fcf863d926055d9fa458db46e0d3 (patch)
tree1fd262ac79127e60d91f9e7efac9702ec3058cdb /server/src/fs_utils.rs
parent42334c32226f0ff3248d6d0c7641b7170ca962ce (diff)
Add basic git support
Pushing a commit to a new branch creates a review. Each project has its own git directory, with githooks installed that talkes with server process via unix sockets.
Diffstat (limited to 'server/src/fs_utils.rs')
-rw-r--r--server/src/fs_utils.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/server/src/fs_utils.rs b/server/src/fs_utils.rs
new file mode 100644
index 0000000..7905d01
--- /dev/null
+++ b/server/src/fs_utils.rs
@@ -0,0 +1,54 @@
+#![allow(dead_code)]
+
+use std::io;
+use std::path::Path;
+use tokio::fs;
+
+pub async fn create_dir_allow_existing(path: impl AsRef<Path>) -> io::Result<()> {
+ match fs::create_dir(path).await {
+ Ok(_) => Ok(()),
+ Err(e) => {
+ if e.kind() == io::ErrorKind::AlreadyExists {
+ Ok(())
+ } else {
+ Err(e)
+ }
+ }
+ }
+}
+
+pub async fn remove_file_allow_not_found(path: impl AsRef<Path>) -> io::Result<()> {
+ match fs::remove_file(path).await {
+ Ok(_) => Ok(()),
+ Err(e) => {
+ if e.kind() == io::ErrorKind::NotFound {
+ Ok(())
+ } else {
+ Err(e)
+ }
+ }
+ }
+}
+
+pub async fn symlink_update_existing(
+ src: impl AsRef<Path>,
+ dst: impl AsRef<Path>,
+) -> io::Result<()> {
+ let src = src.as_ref();
+ let dst = dst.as_ref();
+ match fs::symlink(&src, &dst).await {
+ Ok(_) => Ok(()),
+ Err(e) => {
+ if e.kind() == io::ErrorKind::AlreadyExists {
+ let path = fs::read_link(&dst).await?;
+ if path == src {
+ return Ok(());
+ }
+ fs::remove_file(&dst).await?;
+ fs::symlink(&src, &dst).await
+ } else {
+ Err(e)
+ }
+ }
+ }
+}