Skip to content

fix: Robust symlink handling in installer#295

Closed
edcet wants to merge 1 commit intobevry:masterfrom
edcet:fix/symlink-identical-paths
Closed

fix: Robust symlink handling in installer#295
edcet wants to merge 1 commit intobevry:masterfrom
edcet:fix/symlink-identical-paths

Conversation

@edcet
Copy link
Copy Markdown

@edcet edcet commented May 30, 2025

This PR addresses issues in the Dorothy installer (commands/dorothy) related to symbolic link creation, specifically:

  1. Identical Source/Destination Paths: Prevents "Directory not empty" errors when the installer attempts to create a symlink where the source and destination paths are identical (e.g., ln -s /path/to/dir /path/to/dir). This often occurs with --no-xdg installations.
  2. Broken Symlinks at Target: Ensures that if an identical path scenario is encountered and the target is a broken symlink, the broken symlink is removed.
  3. Missing Parent Directories: Ensures parent directories are created before attempting mv or ln operations within relocation functions, preventing "No such file or directory" errors for __fs_realpath or mv.

Problem Details:

  • The relocate_then_symlink_if_necessary function could fail if $symlink and $destination were the same, as ln -sfF cannot replace a non-empty directory with a symlink to itself.
  • If $symlink was a broken symlink and identical to $destination, the broken link wasn't cleaned up.
  • The relocate_if_necessary function could fail if parent directories for $destination didn't exist before mv or __fs_realpath calls.

Fixes Implemented:

  1. In relocate_then_symlink_if_necessary:
    • Added a check: if $symlink and $destination are identical, it now first removes $symlink if it's a broken symlink, then skips the ln operation.
    • Ensures parent directories for $symlink and $destination are created using mkdir -p at the beginning of the function.
  2. In relocate_if_necessary:
    • Ensures parent directories for $source and $destination are created using mkdir -p at the beginning of the function.

Testing:
Verified on macOS:

  • Installer completes successfully when DOROTHY is set to an existing target directory (testing identical path fix).
  • Installer correctly handles and cleans up broken symlinks when they are also the target of an identical-path symlink operation.
  • Relocation logic correctly creates necessary parent directories, avoiding grealpath errors.

This fixes an issue where the installer would fail with 'Directory not empty' when attempting to create a symlink where the source and destination are identical paths. The problem commonly occurs when installing with DOROTHY pointing to an existing directory.
@balupton
Copy link
Copy Markdown
Member

balupton commented May 30, 2025

Not sure just deleting dorothy is the solution here...

Is this fixed already on the latest dev branch, which is dev/devilbird ? Note that devilbird changes a lot, so you may have breaks/incompatibilities with your user config, it is still under dev so a lot is still broken - however, I recall I may have rewritten the broken functionality already.

@edcet edcet closed this May 30, 2025
@edcet edcet deleted the fix/symlink-identical-paths branch May 30, 2025 18:34
@edcet
Copy link
Copy Markdown
Author

edcet commented May 30, 2025

Apologies for the noise.

@balupton balupton mentioned this pull request Nov 6, 2025
28 tasks
@balupton
Copy link
Copy Markdown
Member

balupton commented Nov 6, 2025

#281 is now merged which fixes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants