Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accidental file deletion when linking #360

Open
MooseV2 opened this issue Mar 22, 2024 · 0 comments
Open

Accidental file deletion when linking #360

MooseV2 opened this issue Mar 22, 2024 · 0 comments

Comments

@MooseV2
Copy link

MooseV2 commented Mar 22, 2024

While configuring my dotbot config, I ran into an issue that caught me off guard and led to the accidental deletion of source files.

# Directory structure
dotbot.yml
t_source/
------> /config.json
# Initial dotbot.yml
- defaults:
    link:
      relink: true
      create: true
      force: true

- link:
    t_target: t_source

After running dotbot -c dotbot.yml, I get the following

$ dotbot -c dotbot.yml
Creating link t_target -> /home/user/test/t_source
All links have been set up

==> All tasks executed successfully

$ ls -l
-rw-rw-r-- 1 user user  110 Mar 21 22:48 dotbot.yml
drwxrwxr-x 2 user user 4096 Mar 21 22:47 t_source/
lrwxrwxrwx 1 user user   27 Mar 21 22:50 t_target -> /home/user/test/t_source/

$ ls t_target
config.json

Now, I wanted to change my config to instead link the file directly (config.json) instead of the directory (t_source).

    - link:
-       t_target: t_source
+       t_target/config.json: t_source/config.json

Here is where the issue lies. Remember:

  1. t_target is a symlink pointing to t_source
  2. t_target/config.json exists since we previously linked it.

So when dotbot goes to link this file, it sees that t_target/config.json exists and deletes it to make room for the new link. Since this points to the real original file, t_source/config.json is deleted!

$ ls t_source/config.json
t_source/config.json

$ dotbot -c dotbot.yml
Removing t_target/config.json
Nonexistent source for t_target/config.json : /home/user/test/t_source/config.json
Some links were not successfully set up

==> Some tasks were not executed successfully

$ ls t_source/config.json
ls: cannot access 't_source/config.json': No such file or directory

This is fundamentally user error, but I think it's worth putting some checks around since not only did it delete my source file, but it wasn't clear why it did it until I took some time to investigate.

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

No branches or pull requests

1 participant