Skip to content

afpd: use utimensat when storing kMDItemLastUsedDate for Spotlight#2897

Merged
andylemin merged 1 commit intomainfrom
rdmark-utime-fix
Apr 19, 2026
Merged

afpd: use utimensat when storing kMDItemLastUsedDate for Spotlight#2897
andylemin merged 1 commit intomainfrom
rdmark-utime-fix

Conversation

@rdmark
Copy link
Copy Markdown
Member

@rdmark rdmark commented Apr 18, 2026

The previous utime() call left utimbuf.modtime uninitialised on the stack. utime() writes both atime and mtime, so the file's mtime was clobbered with garbage. Apps such as TextEdit compare the mtime they recorded at open time against the current mtime before saving; seeing an unexpected change they abort the save with "file modified by another application".

Replace the utime() call with utimensat(AT_FDCWD, path, ts, 0) where ts[1].tv_nsec = UTIME_OMIT, which updates only the access time and leaves the modification time strictly unchanged.

Fixes breakage introduced in #2878

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 18, 2026

🤖 Augment PR Summary

Summary: Updates Spotlight attribute storage so writing kMDItemLastUsedDate no longer corrupts file mtime.

Changes: Switches the atime update path from utime() to utimensat() with UTIME_OMIT to preserve mtime while still recording “last used” access time.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread etc/afpd/spotlight.c
Comment thread etc/afpd/spotlight.c
@rdmark
Copy link
Copy Markdown
Member Author

rdmark commented Apr 19, 2026

augment review

Comment thread etc/afpd/spotlight.c Fixed
Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread etc/afpd/spotlight.c
Comment thread etc/afpd/spotlight.c Outdated
The previous utime() call left utimbuf.modtime uninitialised on the
stack. utime() writes both atime and mtime, so the file's mtime was
clobbered with garbage. Apps such as TextEdit compare the mtime they
recorded at open time against the current mtime before saving; seeing
an unexpected change they abort the save with "file modified by another
application".

Replace the utime() call with utimensat(AT_FDCWD, path, ts, 0) where
ts[1].tv_nsec = UTIME_OMIT, which updates only the access time and
leaves the modification time strictly unchanged.
@rdmark rdmark force-pushed the rdmark-utime-fix branch from 823f3e6 to 4d94b49 Compare April 19, 2026 06:43
@rdmark rdmark changed the title afpd: use utimensat() when storing kMDItemLastUsedDate for Spotlight afpd: use utimensat when storing kMDItemLastUsedDate for Spotlight Apr 19, 2026
@sonarqubecloud
Copy link
Copy Markdown

@rdmark rdmark requested a review from andylemin April 19, 2026 06:47
@rdmark
Copy link
Copy Markdown
Member Author

rdmark commented Apr 19, 2026

augment review

@github-actions
Copy link
Copy Markdown
Contributor

🔥 Spectest (AFP 3.4) - Flamegraph (AFP_ASSERT active)

Commit: 4d94b49e48bd6a1c5db5a220dd6682edc49c5e67
Profiling: On-CPU sampling @ 1009 Hz (prime), DWARF call-graph, x86_64
Build: debugoptimized (-O2 -g -fno-omit-frame-pointer)
Total Runtime: 66s, Netatalk Code-time: 4.1%,
Stacks: 1977, SVG size: 1.2M

🔥 Open interactive Flamegraph (SVG)

Flamegraph preview

📥 Download from artifacts →

🔝 Top 10 leaf functions
Function Samples
finish_task_switch.isra.0 578790720
do_syscall_64 397423080
_raw_spin_unlock_irqrestore 261645120
__cp_end 161546040
srso_alias_safe_ret 72348840
__syscall_cp_c 46580760
dircache_process_deferred_chain 45589680
x64_sys_call 42616440
__x64_sys_close 34687800
handle_softirqs 23785920

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@andylemin andylemin merged commit fa607d9 into main Apr 19, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants