Skip to content

Commit 070c83b

Browse files
committed
Enable utimensat on Darwin
1 parent f65ba39 commit 070c83b

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎graalpython/com.oracle.graal.python.test/src/tests/test_posix.py‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,17 +672,27 @@ def test_lutimes(self):
672672
self.assertTrue(os.stat(TEST_FULL_PATH2, follow_symlinks=False).st_atime > 900000000)
673673

674674
def test_utimensat(self):
675-
if sys.platform == 'darwin':
676-
with self.assertRaises(NotImplementedError):
677-
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=(952468575678901234, 1579569825123456789))
675+
timestamps = (952468575678901234, 1579569825123456789)
676+
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=timestamps)
677+
stat_result = os.stat(TEST_FULL_PATH2)
678+
if __graalpython__.posix_module_backend() == 'java':
679+
self.assertEqual(timestamps[0] // 1_000_000_000, stat_result.st_atime_ns // 1_000_000_000)
680+
self.assertEqual(timestamps[1] // 1_000_000_000, stat_result.st_mtime_ns // 1_000_000_000)
678681
else:
679-
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=(952468575678901234, 1579569825123456789))
680-
self.assertTrue(os.stat(TEST_FULL_PATH2).st_atime > 900000000)
682+
self.assertEqual(timestamps[0], stat_result.st_atime_ns)
683+
self.assertEqual(timestamps[1], stat_result.st_mtime_ns)
681684

682685
def test_futimes_and_futimens(self):
683686
with open(TEST_FULL_PATH2, os.O_RDWR) as fd:
684-
os.utime(fd, times=(12345, 67890))
685-
self.assertTrue(abs(os.stat(TEST_FULL_PATH1).st_atime_ns - 12345000000000) < 10000000000)
687+
timestamps = (12345678901234, 67890123456789)
688+
os.utime(fd, ns=timestamps)
689+
stat_result = os.stat(TEST_FULL_PATH1)
690+
if __graalpython__.posix_module_backend() == 'java':
691+
self.assertEqual(timestamps[0] // 1_000_000_000, stat_result.st_atime_ns // 1_000_000_000)
692+
self.assertEqual(timestamps[1] // 1_000_000_000, stat_result.st_mtime_ns // 1_000_000_000)
693+
else:
694+
self.assertEqual(timestamps[0], stat_result.st_atime_ns)
695+
self.assertEqual(timestamps[1], stat_result.st_mtime_ns)
686696

687697
@unittest.skipUnless(sys.platform != 'darwin', 'faccessat on MacOSX does not support follow_symlinks')
688698
def test_access(self):

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixConstantsDarwin.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,8 +48,8 @@ private PosixConstantsDarwin() {
4848
}
4949

5050
static void getConstants(PosixConstants.Registry constants) {
51-
constants.put("HAVE_FUTIMENS", false);
52-
constants.put("HAVE_UTIMENSAT", false);
51+
constants.put("HAVE_FUTIMENS", true);
52+
constants.put("HAVE_UTIMENSAT", true);
5353
constants.put("FD_SETSIZE", 1024);
5454
constants.put("PATH_MAX", 1024);
5555
constants.put("L_ctermid", 1024);

‎graalpython/python-libposix/src/posix.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ void call_rewinddir(intptr_t dirp) {
25002500
rewinddir((DIR *) dirp);
25012501
}
25022502

2503-
#ifdef __gnu_linux__
2503+
#if defined(__gnu_linux__) || defined(__APPLE__)
25042504
int32_t call_utimensat(int32_t dirFd, const char *path, int64_t *timespec, int32_t followSymlinks) {
25052505
if (!timespec) {
25062506
CAPTURE_ERRNO_AND_RETURN(-1, utimensat(dirFd, path, NULL, followSymlinks ? 0 : AT_SYMLINK_NOFOLLOW));

‎scripts/gen_native_cfg.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
# Column #2 - type specifier:
119119
# `i` - int
120120
# `x` - int, appearing in hexadecimal in the generated source
121-
# `b` - boolean, will be true if the plaform is Linux (WTF?)
121+
# `b` - boolean, will be true on POSIX platforms
122122
# Column #3 - the name of the constant
123123
# Comments can come after that starting with "//"
124124
constant_defs = '''
@@ -654,7 +654,7 @@ def generate_platform():
654654
f.write('\nint main() {\n')
655655
for c in constants:
656656
if c.format is None:
657-
val = 'true' if platform == 'Linux' else 'false'
657+
val = 'true' if platform in ('Linux', 'Darwin') else 'false'
658658
f.write(f' printf(" constants.put(\\"{c.name}\\", {val});\\n");\n')
659659
continue
660660
if c.optional:

0 commit comments

Comments
 (0)