Skip to content

fix: back up existing files instead of deleting during symlink restore#40

Merged
yarlson merged 1 commit into
mainfrom
fix/safer-overwrite
Feb 28, 2026
Merged

fix: back up existing files instead of deleting during symlink restore#40
yarlson merged 1 commit into
mainfrom
fix/safer-overwrite

Conversation

@yarlson

@yarlson yarlson commented Feb 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • During RestoreSymlinks (called by lnk pull), existing regular files/directories at the symlink target are now backed up to <path>.lnk-backup instead of silently deleted via os.RemoveAll
  • Stale symlinks (pointing to wrong targets) are still removed directly — this is safe
  • Prevents accidental data loss when a user has a real file where lnk wants to place a symlink

Closes #24

Test plan

  • Added TestRestoreSymlinksBackupsExistingFile that verifies:
    • A regular file at the target path gets renamed to .lnk-backup
    • The backup contains the original content
    • The symlink is correctly created
  • Full test suite passes locally

…nk restore

When RestoreSymlinks encounters a regular file or directory at the
symlink target path, it now renames it to <path>.lnk-backup instead
of calling os.RemoveAll. Stale symlinks are still removed directly.

Closes #24
@yarlson yarlson merged commit f6e88b9 into main Feb 28, 2026
7 checks passed
@yarlson yarlson deleted the fix/safer-overwrite branch February 28, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safer overwriting

1 participant