Skip to content

Commit efb6cd7

Browse files
committed
moduos: Move times==None handling to filesystems code.
Because qemu-arm port does not support mp_hal_time_ns().
1 parent a65a33f commit efb6cd7

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

extmod/vfs.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_vfs_statvfs_obj, mp_vfs_statvfs);
531531
mp_obj_t mp_vfs_utime(size_t n_args, const mp_obj_t *args) {
532532
mp_obj_t path_in = args[0];
533533
mp_obj_t times_in = (n_args > 1) ? args[1] : mp_const_none;
534-
if (times_in == mp_const_none) {
535-
// If times not supplied or set to None, use current time
536-
mp_obj_t t = mp_obj_new_int_from_ull(mp_hal_time_ns() / 1000000000ULL);
537-
times_in = mp_obj_new_tuple(2, (mp_obj_t[2]) {t, t});
538-
}
539534
mp_obj_t args_out[2] = {MP_OBJ_NULL, times_in};
540535
mp_vfs_mount_t *vfs = lookup_path(path_in, &args_out[0]);
541536
return mp_vfs_proxy_call(vfs, MP_QSTR_utime, 2, args_out);

extmod/vfs_fat.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ STATIC mp_obj_t fat_vfs_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_
382382
if (path[0] == 0 || (path[0] == '/' && path[1] == 0)) {
383383
mp_raise_OSError(MP_EPERM);
384384
}
385+
if (times_in == mp_const_none) {
386+
// If times not supplied or set to None, use current time
387+
mp_obj_t t = mp_obj_new_int_from_ull(mp_hal_time_ns() / 1000000000ULL);
388+
times_in = mp_obj_new_tuple(2, (mp_obj_t[2]) {t, t});
389+
}
385390
// times_in = (atime, mtime). Ignore atime and just set mtime
386391
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(times_in);
387392
if (!mp_obj_is_type(times_in, &mp_type_tuple) || tuple->len != 2) {

extmod/vfs_lfsx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,11 @@ STATIC mp_obj_t MP_VFS_LFSx(utime)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t
448448
const char *path = MP_VFS_LFSx(make_path)(self, path_in);
449449

450450
if (self->enable_mtime) {
451+
if (times_in == mp_const_none) {
452+
// If times not supplied or set to None, use current time
453+
mp_obj_t t = mp_obj_new_int_from_ull(mp_hal_time_ns() / 1000000000ULL);
454+
times_in = mp_obj_new_tuple(2, (mp_obj_t[2]) {t, t});
455+
}
451456
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(times_in);
452457
if (!mp_obj_is_type(times_in, &mp_type_tuple) || tuple->len != 2) {
453458
mp_raise_OSError(MP_EINVAL);

extmod/vfs_posix.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,22 +336,31 @@ STATIC mp_obj_t vfs_posix_utime(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t tim
336336
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
337337
const char *path = vfs_posix_get_path_str(self, path_in);
338338
// times_in = (atime, mtime).
339+
if (times_in == mp_const_none) {
340+
// If times not supplied or set to None, use current time
341+
mp_obj_t t = mp_obj_new_int_from_ull(mp_hal_time_ns() / 1000000000ULL);
342+
times_in = mp_obj_new_tuple(2, (mp_obj_t[2]) {t, t});
343+
}
339344
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(times_in);
340345
if (!mp_obj_is_type(times_in, &mp_type_tuple) || tuple->len != 2) {
341346
mp_raise_OSError(MP_EINVAL);
342347
}
343348
#if 0
349+
// utime() is obsoleted for utimes() in posix.1-2008, but not supported on windows port.
344350
struct timeval times[2] = {
345351
{mp_obj_get_int(tuple->items[0]), 0},
346352
{mp_obj_get_int(tuple->items[1]), 0},
347353
};
354+
int ret;
355+
MP_HAL_RETRY_SYSCALL(ret, utimes(path, &times[0]), mp_raise_OSError(err));
348356
#else
349-
struct utimbuf times[1] = {
350-
{ mp_obj_get_int(tuple->items[0]), mp_obj_get_int(tuple->items[1]) }
357+
struct utimbuf times = {
358+
mp_obj_get_int(tuple->items[0]),
359+
mp_obj_get_int(tuple->items[1])
351360
};
352-
#endif
353361
int ret;
354-
MP_HAL_RETRY_SYSCALL(ret, utime(path, &times[0]), mp_raise_OSError(err));
362+
MP_HAL_RETRY_SYSCALL(ret, utime(path, &times), mp_raise_OSError(err));
363+
#endif
355364
return mp_const_none;
356365
}
357366
STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_utime_obj, vfs_posix_utime);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy