Skip to content

Commit 3780af3

Browse files
committed
[GR-30009] Use to utimes/futimes/lutimes on Mac OS X Sierra
PullRequest: graalpython/1681
2 parents 2a89f1b + 0393949 commit 3780af3

File tree

14 files changed

+371
-104
lines changed

14 files changed

+371
-104
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "d8d57ccfe5a0a2b1ef094be4772d4f01c2dfb2cb" }
1+
{ "overlay": "170e550ee492b57eddde3fbe3e2334bcf3ff5d5f" }

graalpython/com.oracle.graal.python.cext/posix/posix.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <sys/ioctl.h>
6060
#include <sys/stat.h>
6161
#include <sys/select.h>
62+
#include <sys/time.h>
6263
#include <sys/types.h>
6364
#include <sys/utsname.h>
6465
#include <sys/wait.h>
@@ -362,6 +363,7 @@ int32_t call_readdir(intptr_t dirp, char *nameBuf, uint64_t nameBufSize, int64_t
362363
return 0;
363364
}
364365

366+
#ifdef __gnu_linux__
365367
int32_t call_utimensat(int32_t dirFd, const char *path, int64_t *timespec, int32_t followSymlinks) {
366368
if (!timespec) {
367369
return utimensat(dirFd, path, NULL, followSymlinks ? 0 : AT_SYMLINK_NOFOLLOW);
@@ -387,6 +389,46 @@ int32_t call_futimens(int32_t fd, int64_t *timespec) {
387389
return futimens(fd, times);
388390
}
389391
}
392+
#endif
393+
394+
int32_t call_futimes(int32_t fd, int64_t *timeval) {
395+
if (!timeval) {
396+
return futimes(fd, NULL);
397+
} else {
398+
struct timeval times[2];
399+
times[0].tv_sec = timeval[0];
400+
times[0].tv_usec = timeval[1];
401+
times[1].tv_sec = timeval[2];
402+
times[1].tv_usec = timeval[3];
403+
return futimes(fd, times);
404+
}
405+
}
406+
407+
int32_t call_lutimes(const char *filename, int64_t *timeval) {
408+
if (!timeval) {
409+
return lutimes(filename, NULL);
410+
} else {
411+
struct timeval times[2];
412+
times[0].tv_sec = timeval[0];
413+
times[0].tv_usec = timeval[1];
414+
times[1].tv_sec = timeval[2];
415+
times[1].tv_usec = timeval[3];
416+
return lutimes(filename, times);
417+
}
418+
}
419+
420+
int32_t call_utimes(const char *filename, int64_t *timeval) {
421+
if (!timeval) {
422+
return utimes(filename, NULL);
423+
} else {
424+
struct timeval times[2];
425+
times[0].tv_sec = timeval[0];
426+
times[0].tv_usec = timeval[1];
427+
times[1].tv_sec = timeval[2];
428+
times[1].tv_usec = timeval[3];
429+
return utimes(filename, times);
430+
}
431+
}
390432

391433
int32_t call_renameat(int32_t oldDirFd, const char *oldPath, int32_t newDirFd, const char *newPath) {
392434
return renameat(oldDirFd, oldPath, newDirFd, newPath);

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,28 +344,32 @@ def test_fstat(self):
344344
with open(TEST_FULL_PATH2, 0) as fd: # follows symlink
345345
self.assertEqual(inode, os.fstat(fd).st_ino)
346346

347-
def test_utime_basic(self):
348-
stat_result = os.stat(TEST_FULL_PATH1)
347+
def test_utimes(self):
349348
os.utime(TEST_FULL_PATH2, (-952468575.678901234, 1579569825.123456789)) # follows symlink
350349
self.assertTrue(os.stat(TEST_FULL_PATH1).st_atime < -900000000)
351-
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=(stat_result.st_atime_ns, stat_result.st_mtime_ns))
352-
self.assertTrue(abs(os.stat(TEST_FULL_PATH1).st_atime - stat_result.st_atime) < 10)
353-
with open(TEST_FULL_PATH2, os.O_RDWR) as fd:
354-
os.utime(fd, times=(12345, 67890))
355-
self.assertTrue(abs(os.stat(TEST_FULL_PATH1).st_atime_ns - 12345000000000) < 10000000000)
350+
351+
def test_utimes(self):
352+
os.utime(TEST_FULL_PATH2)
356353

357354
@unittest.skipUnless(__graalpython__.posix_module_backend() != 'java',
358355
'Due to bug in OpenJDK 8 on Linux we cannot set atime/mtime of symlinks')
359-
def test_utime_basic_no_follow_symlinks(self):
360-
stat_result = os.stat(TEST_FULL_PATH1)
356+
def test_lutimes(self):
361357
os.utime(TEST_FULL_PATH2, (-952468575.678901234, 1579569825.123456789)) # follows symlink
362358
self.assertTrue(os.stat(TEST_FULL_PATH1).st_atime < -900000000)
363359
os.utime(TEST_FULL_PATH2, ns=(952468575678901234, 1579569825123456789), follow_symlinks=False)
364360
self.assertTrue(os.stat(TEST_FULL_PATH1).st_atime < -900000000)
365361
self.assertTrue(abs(os.stat(TEST_FULL_PATH1).st_mtime - 1579569825) < 10)
366362
self.assertTrue(os.stat(TEST_FULL_PATH2, follow_symlinks=False).st_atime > 900000000)
367-
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=(stat_result.st_atime_ns, stat_result.st_mtime_ns))
368-
self.assertTrue(abs(os.stat(TEST_FULL_PATH1).st_atime - stat_result.st_atime) < 10)
363+
364+
def test_utimensat(self):
365+
if sys.platform == 'darwin':
366+
with self.assertRaises(NotImplementedError):
367+
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=(952468575678901234, 1579569825123456789))
368+
else:
369+
os.utime(TEST_FILENAME2, dir_fd=self.tmp_fd, ns=(952468575678901234, 1579569825123456789))
370+
self.assertTrue(os.stat(TEST_FULL_PATH2).st_atime > 900000000)
371+
372+
def test_futimes_and_futimens(self):
369373
with open(TEST_FULL_PATH2, os.O_RDWR) as fd:
370374
os.utime(fd, times=(12345, 67890))
371375
self.assertTrue(abs(os.stat(TEST_FULL_PATH1).st_atime_ns - 12345000000000) < 10000000000)

0 commit comments

Comments
 (0)