diff options
author | Óscar Nájera <hi@oscarnajera.com> | 2020-10-20 00:24:05 +0200 |
---|---|---|
committer | Óscar Nájera <hi@oscarnajera.com> | 2020-10-20 00:24:05 +0200 |
commit | 311d07fa91cefca23c304ed51e8022b2a3a6c736 (patch) | |
tree | 3cdbc3c8b57534790c3136c73588192a22314837 | |
parent | 5ffbfd395e32cbbaa2e9d3e5855b1ac4c2d3332a (diff) | |
download | dotfiles-311d07fa91cefca23c304ed51e8022b2a3a6c736.tar.gz dotfiles-311d07fa91cefca23c304ed51e8022b2a3a6c736.tar.bz2 dotfiles-311d07fa91cefca23c304ed51e8022b2a3a6c736.zip |
Fix symlinking
Do nothing if on desired state.
Remove file on target location if it something is found.
-rwxr-xr-x | install.scm | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/install.scm b/install.scm index 2b0e7cb..dfb85af 100755 --- a/install.scm +++ b/install.scm @@ -52,15 +52,22 @@ (string-append prefix (substring f user-end (string-length f))))) (else (string-append (getcwd) "/" f)))) +(define (symlink? path) + (false-if-exception + (eq? 'symlink (stat:type (lstat path))))) + (define (clean-file full-dest) - (when (file-exists? full-dest) + (when (false-if-exception (lstat full-dest)) (log-msg 'WARN (string-append "Deleting previous file: " full-dest)) - (delete-file full-dest)) - full-dest) + (delete-file full-dest))) (define (config-links title src target) - (symlink (expand-file src) (clean-file (expand-file target))) - (log-msg 'OK (string-append title " on " target))) + (let ((src-path (expand-file src)) + (target-path (expand-file target))) + (unless (and (symlink? target-path) (equal? (readlink target-path) src-path)) + (clean-file target-path) + (symlink src-path target-path) + (log-msg 'OK (string-append title " on " target))))) (define (git-config) (log-msg 'INFO "Configuring git") |