Skip to content

image: Skip creating lock file if short-name-aliases.conf is missing#969

Open
Lekensteyn wants to merge 1 commit into
podman-container-tools:mainfrom
Lekensteyn:skip-short-name-lock-ro
Open

image: Skip creating lock file if short-name-aliases.conf is missing#969
Lekensteyn wants to merge 1 commit into
podman-container-tools:mainfrom
Lekensteyn:skip-short-name-lock-ro

Conversation

@Lekensteyn

@Lekensteyn Lekensteyn commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

@mtrmac mtrmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread image/pkg/sysregistriesv2/shortnames.go Outdated
Comment thread image/pkg/sysregistriesv2/shortnames_test.go Outdated
Comment thread image/pkg/sysregistriesv2/shortnames_test.go Outdated
@Lekensteyn Lekensteyn force-pushed the skip-short-name-lock-ro branch from bb9be0c to 6c5fc25 Compare July 8, 2026 22:30
@Lekensteyn

Copy link
Copy Markdown
Contributor Author

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.

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.

Comment thread image/pkg/sysregistriesv2/shortnames.go Outdated
Comment thread image/pkg/sysregistriesv2/shortnames.go Outdated
return nil, "", err
}
if !errors.Is(fileutils.Exists(confPath), fs.ErrNotExist) {
// Conf file exists, create lock file to avoid conflicting writes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Lekensteyn Lekensteyn Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread image/pkg/sysregistriesv2/shortnames.go Outdated
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>
@Lekensteyn Lekensteyn force-pushed the skip-short-name-lock-ro branch from 6c5fc25 to 314548e Compare July 9, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

image Related to "image" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants