Skip to content

Fix utime sometimes failing #1826

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion osxphotos/fileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing as t
from abc import ABC, abstractmethod
from tempfile import TemporaryDirectory
import fcntl

from .imageconverter import ImageConverter
from .platform import is_macos
Expand Down Expand Up @@ -163,7 +164,26 @@ def rmdir(cls, dirpath):
def utime(cls, path, times):
"""Set the access and modified time of path."""
path = normalize_fs_path(path)
os.utime(path, times=times)

fd = None
try:
# Open file and set F_NOCACHE to prevent filesystem cache interference
fd = os.open(path, os.O_RDONLY)
fcntl.fcntl(fd, fcntl.F_NOCACHE, 1)

os.utime(path, times)
return True
finally:
if fd is not None:
try:
# Clear F_NOCACHE flag before closing
fcntl.fcntl(fd, fcntl.F_NOCACHE, 0)
os.close(fd)
except:
try:
os.close(fd)
except:
pass

@classmethod
def cmp(cls, f1, f2, mtime1=None):
Expand Down
Loading