-
Notifications
You must be signed in to change notification settings - Fork 27
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
Make it fast and easy to do multiple replacements #13
Comments
My first reaction is that this probably doesn’t belong into the renameio package, but of course we can revisit that later. As for how to solve the problem, I’d suggest to get the list of mounts ( What do you think? |
Hmmm, I think this does fit in the I don't think it's necessary to parse the mount table. Another way to do it would be to |
I actually don’t see how? AFAIK, the only portable way across unices is what renameio implements. Other packages (which I have surveyed in golang/go#22397 (comment)) use the same approach. The implementation you’re suggesting in #15 does not seem to require access to any internals of the renameio package. Hence, I’d prefer it if we could keep it in a separate import path (at least) until we know that it’s useful for a number of people.
That’s true, but parsing the mount table can be done once at startup, whereas using |
It's only necessary to call A problem with parsing the mount table is that you then have to work out the relationship between the destination directory and the mount points. This is a hard problem and simple string prefix matching is definitely insufficient (see the discussion in golang/go#18358). |
That’s a fair point. I suppose the stat-based cache is a good solution. Can you make use of it in chezmoi and we’ll move it to renameio once other people need it, too? |
Yup, sounds good. |
FWIW, twpayne/chezmoi#208 should fix this in |
chezmoi
usesrenameio
to ensure that files in the user's home directory are replaced atomically.renameio.TempDir
takes the name of the directory where the file replacement will take place so that it can determine a suitable location for the interim file with which the final destination file will be replaced.chezmoi
callsrenameio.TempDir
once based on the destination directory, but this implicitly assumes that the user's home directory is on a single filesystem. If the user's home directory spans multiple filesystems then different temporary directories will be needed. If the user's home directory is on a single filesystem then the same temporary directory can be re-used.The safe path is to call
renameio.TempDir
for every file replacement, but this is very slow (chezmoi
might change thousands of files, there's no need to create thousands of temporary directories when only one is needed).I think
renameio
needs a function like:The text was updated successfully, but these errors were encountered: