Repository: comtrya/comtrya (language: rust)

Issue:
Bug: can't rerun file.link
## Bug Report

### Steps to reproduce

1. Add a `file.link` action
2. Apply the manifest (by running `comtrya`)
3. Observe that symlink exists
4. Apply the manifest again
5. Get an error

### Expected behaviour

- if the correct symlink already exists, do nothing
- if the file exists and is not the correct symlink, emit an error (warning?)



Discussion / hints:

Fix patch:
diff --git a/src/actions/file/link.rs b/src/actions/file/link.rs
index 84d4ff43..ea81fa92 100644
--- a/src/actions/file/link.rs
+++ b/src/actions/file/link.rs
@@ -39,7 +39,20 @@ impl Action for FileLink {
         let from = self.resolve(manifest, &self.from).unwrap();
         let to = PathBuf::from(&self.to);
 
-        create_link(from, to)
+        match to.read_link() {
+            Ok(symlink) => {
+                if from.eq(&symlink) {
+                    Ok(ActionResult {
+                        message: String::from("Already present"),
+                    })
+                } else {
+                    Err(ActionError {
+                        message: String::from("Symlink exists to another file"),
+                    })
+                }
+            }
+            Err(_) => create_link(from, to),
+        }
     }
 }
 
diff --git a/src/main.rs b/src/main.rs
index 0ac19926..3181d2dc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -278,7 +278,9 @@ fn main() {
                 };
 
                 match result {
-                    Ok(_) => (),
+                    Ok(result) => {
+                        debug!("{}", result.message)
+                    }
                     Err(e) => {
                         successful = false;
 


Test patch: