macOS: fix TypeError when _get_birthtime_ns gets called with an FD

Crashed when trying to os.fsdecode(path) when path is an int.
This commit is contained in:
Thomas Waldmann 2026-05-12 18:15:00 +02:00
parent ca3e88f5b1
commit 2bb9e4889b
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -190,13 +190,15 @@ def _get_birthtime_ns(path, follow_symlinks=False):
cdef int result
if isinstance(path, int):
result = c_fstat(path, &stat_info)
if result != 0:
raise OSError(errno.errno, os.strerror(errno.errno), "<FD %d>" % path)
else:
if follow_symlinks:
result = c_stat(path, &stat_info)
else:
result = c_lstat(path, &stat_info)
if result != 0:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
if result != 0:
raise OSError(errno.errno, os.strerror(errno.errno), os.fsdecode(path))
return stat_info.st_birthtimespec.tv_sec * 1_000_000_000 + stat_info.st_birthtimespec.tv_nsec