diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 6d5bfbe205..3a1bdb29c5 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -415,18 +415,23 @@ STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); -STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t time_in) { +STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_in); - const int time = mp_obj_get_int(time_in); + if (!mp_obj_is_tuple_compatible(times_in)) { + mp_raise_type_arg(&mp_type_TypeError, times_in); + } + mp_obj_t *times; + mp_obj_get_array_fixed_n(times_in, 2, ×); + const int atime = mp_obj_get_int(times[0]); + const int mtime = mp_obj_get_int(times[1]); timeutils_struct_time_t tm; - timeutils_seconds_since_epoch_to_struct_time(time, &tm); + timeutils_seconds_since_epoch_to_struct_time(atime, &tm); FILINFO fno; fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday); fno.ftime = (WORD)(tm.tm_hour * 2048U | tm.tm_min * 32U | tm.tm_sec / 2U); - FRESULT res = f_utime(&self->fatfs, path, &fno); if (res != FR_OK) { mp_raise_OSError_fresult(res); diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index 54e33b3835..684b0d1735 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -247,13 +247,13 @@ STATIC mp_obj_t os_urandom(mp_obj_t size_in) { } MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom); -//| def utime(path: str, time: int) -> None: +//| def utime(path: str, times: Tuple[int, int]) -> None: //| """Change the timestamp of a file.""" //| ... //| -STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t time_in) { +STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t times_in) { const char *path = mp_obj_str_get_str(path_in); - common_hal_os_utime(path, time_in); + common_hal_os_utime(path, times_in); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(os_utime_obj, os_utime); diff --git a/shared-bindings/os/__init__.h b/shared-bindings/os/__init__.h index 749d74baa2..00d8c28a50 100644 --- a/shared-bindings/os/__init__.h +++ b/shared-bindings/os/__init__.h @@ -45,7 +45,7 @@ void common_hal_os_rename(const char *old_path, const char *new_path); void common_hal_os_rmdir(const char *path); mp_obj_t common_hal_os_stat(const char *path); mp_obj_t common_hal_os_statvfs(const char *path); -void common_hal_os_utime(const char *path, mp_obj_t time); +void common_hal_os_utime(const char *path, mp_obj_t times); // Returns true if data was correctly sourced from a true random number generator. bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length); diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c index e7d49c1a6b..200fcb2f61 100644 --- a/shared-module/os/__init__.c +++ b/shared-module/os/__init__.c @@ -227,9 +227,9 @@ mp_obj_t common_hal_os_statvfs(const char *path) { return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out); } -void common_hal_os_utime(const char *path, mp_obj_t time) { +void common_hal_os_utime(const char *path, mp_obj_t times) { mp_obj_t args[2]; mp_vfs_mount_t *vfs = lookup_path(path, &args[0]); - args[1] = time; + args[1] = times; mp_vfs_proxy_call(vfs, MP_QSTR_utime, 2, args); }