Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Continue to next file / task when pressing 'n' at clobber prompt#32

Merged
FooSoft merged 2 commits intoFooSoft:masterfrom
albertdev:bugfix/rework-clobber-prompt
Dec 14, 2021
Merged

Continue to next file / task when pressing 'n' at clobber prompt#32
FooSoft merged 2 commits intoFooSoft:masterfrom
albertdev:bugfix/rework-clobber-prompt

Conversation

@albertdev
Copy link
Contributor

@albertdev albertdev commented Sep 13, 2021

A prompt shows up if Homemaker detects an existing file when creating a link or running a template.
Pressing n might stop the problematic file from being removed, but homemaker will still continue:

clobber path /home/johndoe/.rcfile: [y]es, [n]o? n
2021/09/13 15:22:53 linking /dotfiles/rcfile to /home/johndoe/.rcfile
symlink /dotfiles/rcfile /home/johndoe/.rcfile: Cannot create a file when that file already exists.: [a]bort, [r]etry, [c]ancel?

Pressing c will obviously mean that nothing has happened, but no such luck for templates:

clobber path /home/johndoe/.aliasesfile: [y]es, [n]o? n
2021/09/13 15:24:26 process template /dotfiles/aliasesfile_template to /home/johndoe/.aliasesfile

At this point the target file is overwritten.

This PR shuffles the code around so that the cleanPath() function which shows the "clobber path" prompt can return a boolean, at which point the caller can decide to stop doing what it is doing.

The end user would be prompted if a file is going to be overwritten,
but homemaker would still attempt to do so no matter the answer.

Move the retry-functionality of cleanPath inside this function so that
the function itself can return a boolean to indicate if the calling task
is free to continue. If the path is not clean then homemaker can just
move on to the next file or next task.
@albertdev
Copy link
Contributor Author

My changes are slightly easier to visualize if you review commit by commit. I started in template.go and couldn't spot the helper functions, so I chose to move them from link.go to util.go instead.

@FooSoft
Copy link
Owner

FooSoft commented Dec 14, 2021

Makes sense, sorry for not seeing this earlier.

@FooSoft FooSoft merged commit ddbd7c4 into FooSoft:master Dec 14, 2021
@albertdev albertdev deleted the bugfix/rework-clobber-prompt branch December 14, 2021 22:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants