-
Notifications
You must be signed in to change notification settings - Fork 571
Description
In a necromanced thread a few days ago, the recurring theme of trying to tackle the synchronized removal of files came up again - a chezmoi engineering problem that hasn't been solved yet.
In summery: chezmoi has all of the building blocks to facilitate removal of files, but there is no automated synchronization as it's impossible to detect automatically.
Setting the stage:
Each Instance of chezmoi has 3 potential stages:
- Home - The home directory itself - the working copy.
- Source - The chezmoi source of truth - with all the settings and templates.
- Repo - most commonly git, which allows synchronizations across Instances
What is already in place and working:
- chezmoi destroy - deletes the Home and the Source.
- chezmoi forget - deletes the file from the Source only - does not affect the Home.
remove_source-state-attributed- .chezmoiremove list of files.
Current optimized workflows (as far as I could tell) are:
A: Delete a file from everywhere - Destroy and remove
chezmoi destroy <file>- Add a
remove_<file>blank file in source (or add to .chezmoiremove)
B: Rename a file everywhere - Forget, remove and add
chezmoi forget <file>- rename
<file>to<new_file> - Add a
remove_<file>blank file in source (or add to .chezmoiremove) chezmoi add <new_file>
What can be improved?
The issue I see in common of these two workflows:
- Too many steps for what, fells like, should be a single operation.
remove_source-state-attribute files and.chezmoiremoveare inherently temporary, and left untouched will create clutter and confusion later on.
Proposed solution
I believe I have a possible solution for both issues.
This solution combines 2 separate ideas:
- Automated
remove_source-state-attribute creation - An optional grabage-collection of
remove_files from the source bychezmoi update
Phase 1: * Automated remove_ source-state-attribute creation
- A flag added to
forgetanddestroy(suggestions:--syncor--managed) which would also create theremove_source-state-attribute file.
This will reduce the A workflow into a single action. - A new
mvcommand, which would perform the B workflow in a single action.
Phase 2: Garbage collection
This phase is optional, and can be left to the user to manage on their own.
The idea is to introduce garbage-collection of remove_ source-state-attribute files when chezmoi update is running.
In order for this to work, the actions of Phase 1 above, will create the remove_ files with an expiration date (or a creation date - depending on how you choose to implement it) in ISO format as the content.
I would suggest that chezmoi.toml would allow to modify the default expiration time, but let's say 1 month is a reasnoble default.
When running chezmoi update, it will act as the garbage-collector and delete the remove_ files from the source when the expiration date has passed.
The combination of all these together will provide a complete solution addressing all existing recurring issue, providing a completely automated process of handing this naturally out-of-sync problem.
This proposed solution also allows to keep everything that is already working, and enhance on it.