-
Notifications
You must be signed in to change notification settings - Fork 499
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
Mechanism to manage a directory's content but not the directory itself #3123
Comments
This is really hard to implement given chezmoi's architecture. Basically, chezmoi can cope with entries having different contents across machines, but chezmoi cannot cope with entries being different types across machines (e.g. a symlink on one and a directory on another). Instead, I suggest a different approach. Make |
Your workaround doesn't solve my problem, which isn't to manage the directory Forget about the two hosts and consider the case where
That link can be assumed to already exist. I don't need to manage it with chezmoi. However I want to be able to manage files under My problem is that chezmoi thinks that it has to replace the symbolic link A possible workaround would be to tell chezmoi to ignore changes affecting
Unfortunately, at the moment, the second line doesn't have any effect and all files and directories under A cleaner solution would be to implement a new file name prefix to tell chezmoi that it should only manage the content of the target directory/file but that it shouldn't care about whether it's a real directory/file or a symbolic link. If the target directory/file doesn't already exist, chezmoi should report an error. It could offer to create a real directory/file. I used |
With all due respect, this is your problem, not mine. |
The underlying problem here is that chezmoi is mostly declarative (with the exception of scripts, of course), and this mix of symbolic links and directories is not declarative. chezmoi gets you define what you want the contents of your home directory to be, i.e. what the contents of each file is, and what is a directory and what is a symlink, and The problem with symbolic links and directories comes from walking the filesystem. chezmoi treats symbolic links as first-class citizens, i.e. it treats a symbolic link as a symbolic link, whereas you want chezmoi to treat a symbolic link as the directory that it points to, not as a symbolic link. Treating symbolic links as their targets leads to a whole host of problems. For example, it's easy to create infinite loops (where a symbolic link points to one of its parent directories) or end up in a complex situation where a symbolic link points to a directory on a different filesystem. This is why chezmoi treats symbolic links as symbolic links, and not the targets that they point to. The proposed
Adding |
Sorry, I didn't mean to be offensive. My point was that you misunderstood my actual problem. I tried to re-explain it in a more straightforward way. In short, what would work is either a new file name prefix like |
Thanks for #3123 (comment) ! Hopefully #3123 (comment) explains a bit why. |
I can see how this could work, but I’m not familiar enough with the state internals to be able to make it work, and it has some complexity on the source state, because I believe that If we were to approach this as a prerequisite concept, I think that this might be possible (although it will still require state updates). So, instead of the names proposed, let’s say I’m not sure that I like it, and this might work better with #2273 than trying to fit this into the attribute system as it exists now. |
The thing is that chezmoi seems to be already now smarter than your 3 steps. In fact it looks like implementing a Here is an example to show why I think that chezmoi is already now smarter than your 3 steps. Content of home directory:
Content of /mnt/ directory:
Content of chezmoi source directory:
If I follow your three steps, here is what I expect that chezmoi should propose to do:
But here is the output of
Note that there is no mention of dir/file1.txt. If I run In other words, the |
Yep, that would work. It would also provide a solution for cases where the directory has an unconventional set of file permissions. You could still not create the directory via chezmoi (except maybe with an extra
It's actually two distinct problems. It's true that I initially encountered the problem in a case similar to #2273 but if you look at my example in #3123 (comment), you can see that a single machine is involved. |
@twpayne I also had this problem. The latest solutions described here seem to fix my case as well. |
Is your feature request related to a problem? Please describe.
I have a directory
dir
whose content I would like to manage with chezmoi. However on host A that directory is a real directory while on host B it's a symbolic link to a directory somewhere else:Creating a directory
dir
in my source tree, works perfectly well for host A but not quite so for host B. It does indeed allow to manage the content ofdir
on both hosts. Commands likechezmoi diff dir/file
orchezmoi apply dir/file
have the intended effect on both hosts. The problem is that on host B, chezmoi wants to replace the symbolic linkdir
with a real directorydir
.Describe the solution you'd like
Since the content of the directory is handled correctly on both host and that the only problem is the handling of the directory itself, I was hoping that I could use
.chezmoiignore
to ignore the directory itself but not its content. The documentation of.chezmoiignore
states the following (emphasize mine):I was hoping that adding the following lines to
.chezmoiignore
would do the trick:Unfortunately this has the same effect as if the second line was absent: the directory
dir
and its content are ignored. I have also tried more specific exclusions like!dir/*
or!dir/file
but the result is the same.Describe alternatives you've considered
A possibly cleaner solution to support this use case would be to create a new file prefix (e.g.,
soft_
) to indicate that chezmoi should only manage the content of the target directory (or file) and not its attributes. I could then create a directory namedsoft_dir
in my source repository. Chezmoi would then only require that there is either a target directorydir
or a target symbolic linkdir
that points to a directory. If that isn't the case, it would be an error and chezmoi could offer to create a directory or skip it.The same prefix could also be useful to manage cases where the target directory (or file) has an unsupported set of file permissions, like for example if it's group writeable.
The text was updated successfully, but these errors were encountered: