image: Skip creating lock file if short-name-aliases.conf is missing#969
image: Skip creating lock file if short-name-aliases.conf is missing#969Lekensteyn wants to merge 1 commit into
Conversation
mtrmac
left a comment
There was a problem hiding this comment.
Thanks!
I’m pretty unconvinced this makes much of a difference ultimately — Podman must have writable storage for mount counting and locks, after all — but if it can be done cleanly, why not.
bb9be0c to
6c5fc25
Compare
Thanks for the review! I should've addressed all comments. Yes, writeable storage is required, here I just try to remove unnecessary writes and new directories that would have been empty otherwise. |
| return nil, "", err | ||
| } | ||
| if !errors.Is(fileutils.Exists(confPath), fs.ErrNotExist) { | ||
| // Conf file exists, create lock file to avoid conflicting writes. |
There was a problem hiding this comment.
This comment adds nothing, please drop.
… It’s actually actively misleading in case of a non-ErrNotExist error.
Overall, the code should either only activate on fileutils.Exists() == nil, or it should properly handle the unexpected error cases by reporting them. I think the latter is better, to help the user debug such situations.
There was a problem hiding this comment.
It's intentionally only skipping the branch when the file is definitely missing. For permissions errors and so on, I am purposely ignoring the error and entering the branch. If checking for file existence fails, then creating the lock file will likely produce a better error message.
I can look into bailing out earlier if checking for file existence fails.
There was a problem hiding this comment.
Hum… it’s not obvious to me that if fileutils.Exists fails with an I/O error or something, then accessing/creating a file within will certainly fail, but it’s close enough not to be worth worrying about. So not adding the extra error checking is fair enough.
There was a problem hiding this comment.
I can go either way, right now I have this in the latest pushed version:
err = fileutils.Exists(confPath)
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return nil, "", err
}
if err == nil {
lock, err := getShortNameAliasesLock(confPath)Whereas the err == nil check actually implies the condition !errors.Is(err, fs.ErrNotExist), but I didn't want to call errors.Is twice.
Your call?
The lock file `~/.cache/containers/short-name-aliases.conf.lock` used to be created in all cases, even for read-only attempts for a non-existing `~/.cache/containers/short-name-aliases.conf` file. Do not create this file unless necessary, this keeps the home directory a bit cleaner. Link: podman-container-tools/podman#27921 Signed-off-by: Peter Wu <peter@lekensteyn.nl>
6c5fc25 to
314548e
Compare
The lock file
~/.cache/containers/short-name-aliases.conf.lockused to be created in all cases, even for read-only attempts for a non-existing~/.cache/containers/short-name-aliases.conffile. Do not create this file unless necessary, this keeps the home directory a bit cleaner.Link: podman-container-tools/podman#27921