Skip to content

drivers.ChownPathByMaps(): preserve directory ModTimes#880

Open
nalind wants to merge 2 commits into
podman-container-tools:mainfrom
nalind:chown-preserve-modtime
Open

drivers.ChownPathByMaps(): preserve directory ModTimes#880
nalind wants to merge 2 commits into
podman-container-tools:mainfrom
nalind:chown-preserve-modtime

Conversation

@nalind

@nalind nalind commented May 27, 2026

Copy link
Copy Markdown
Contributor

When changing the ownership throughout a directory tree, make notes of the initial values of the ModTime for directories that we process.

When removing and re-creating hard links to pick up an ownership change, or changing the owner of an directory, note the name of the directory containing the hard link.

After changing the ownership throughout a directory tree, walk the list of directories whose timestamps we expect to have modified, and if their ModTime values were changed, restore them.

@github-actions github-actions Bot added the storage Related to "storage" package label May 27, 2026
@nalind nalind force-pushed the chown-preserve-modtime branch 2 times, most recently from 298e936 to 9027558 Compare May 27, 2026 19:24
@nalind

nalind commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Tests with fuse-overlayfs appear to be stumbling on containers/fuse-overlayfs#400. Do we need to skip the new tests in that configuration?

@nalind nalind force-pushed the chown-preserve-modtime branch 2 times, most recently from ce8d36f to 8ef9805 Compare June 30, 2026 16:36
@packit-as-a-service

Copy link
Copy Markdown

Packit jobs failed. @containers/packit-build please check.

Comment thread storage/drivers/chown.go
Comment thread storage/drivers/chown.go
Comment thread storage/drivers/chown.go Outdated
tsCurrent := syscall.NsecToTimespec(st.ModTime().UnixNano())
tsSaved := syscall.NsecToTimespec(value.(int64))
if tsCurrent != tsSaved {
if err := system.LUtimesNano(dir, []syscall.Timespec{tsSaved, tsSaved}); err != nil {

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 is not supported on macOS, which the code otherwise seems to support.

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.

@nalind I have #955 around for unrelated reasons.

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.

Since tests are suggesting that we don't have to touch every directory, I've dropped the bits in chown_darwin.go that added entries to modifiedDirectories, so the loop should not be entered except on systems where chown_unix.go is doing a remove+link.

@nalind nalind Jul 1, 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.

Okay, adding that back in in chown_unix.go because we flaked on btrfs. I guess that's to be expected?

Comment thread storage/drivers/chown.go Outdated
@nalind nalind force-pushed the chown-preserve-modtime branch from 8ef9805 to 3ca0c9a Compare July 1, 2026 19:47
Comment thread storage/lockfile_compat.go Outdated

// Deprecated: Use lockfile.*LockFile.
type Locker = lockfile.Locker //nolint:staticcheck // SA1019 lockfile.Locker is deprecated
type Locker = lockfile.Locker

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.

There’s some kind of long-standing caching(?) issue. AFAICT the code is correct as is, it’s ”trigger another run and hope it works this time”… Podman is running into a fair bit, it’s quite new for container-libs.

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.

Good to know, I'll drop that commit when I push this next.

@nalind nalind force-pushed the chown-preserve-modtime branch from 6a9f8d2 to f731efb Compare July 1, 2026 20:30
nalind added 2 commits July 1, 2026 17:19
When changing the ownership throughout a directory tree, make notes of
the initial values of the ModTime for directories that we process.

When removing and re-creating hard links to pick up an ownership change,
or changing the owner of an directory, note the name of the directory
containing the hard link, or of the directory itself.

After changing the ownership throughout a directory tree, walk the list
of directories whose timestamps we expect to have modified, and if
their ModTime values were changed, restore them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
@nalind nalind force-pushed the chown-preserve-modtime branch from f731efb to ba14a36 Compare July 1, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage Related to "storage" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants