Skip to content

Commit 71d6496

Browse files
committed
Updated utime() to take a 2-tuple instead of a plain int
1 parent 5a21c30 commit 71d6496

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

extmod/vfs_fat.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,18 +415,23 @@ STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) {
415415
}
416416
STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount);
417417

418-
STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t time_in) {
418+
STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) {
419419
mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in);
420420
const char *path = mp_obj_str_get_str(path_in);
421-
const int time = mp_obj_get_int(time_in);
421+
if (!mp_obj_is_tuple_compatible(times_in)) {
422+
mp_raise_type_arg(&mp_type_TypeError, times_in);
423+
}
422424

425+
mp_obj_t *times;
426+
mp_obj_get_array_fixed_n(times_in, 2, &times);
427+
const int atime = mp_obj_get_int(times[0]);
428+
const int mtime = mp_obj_get_int(times[1]);
423429
timeutils_struct_time_t tm;
424-
timeutils_seconds_since_epoch_to_struct_time(time, &tm);
430+
timeutils_seconds_since_epoch_to_struct_time(atime, &tm);
425431

426432
FILINFO fno;
427433
fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday);
428434
fno.ftime = (WORD)(tm.tm_hour * 2048U | tm.tm_min * 32U | tm.tm_sec / 2U);
429-
430435
FRESULT res = f_utime(&self->fatfs, path, &fno);
431436
if (res != FR_OK) {
432437
mp_raise_OSError_fresult(res);

shared-bindings/os/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ STATIC mp_obj_t os_urandom(mp_obj_t size_in) {
247247
}
248248
MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
249249

250-
//| def utime(path: str, time: int) -> None:
250+
//| def utime(path: str, times: Tuple[int, int]) -> None:
251251
//| """Change the timestamp of a file."""
252252
//| ...
253253
//|
254-
STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t time_in) {
254+
STATIC mp_obj_t os_utime(mp_obj_t path_in, mp_obj_t times_in) {
255255
const char *path = mp_obj_str_get_str(path_in);
256-
common_hal_os_utime(path, time_in);
256+
common_hal_os_utime(path, times_in);
257257
return mp_const_none;
258258
}
259259
MP_DEFINE_CONST_FUN_OBJ_2(os_utime_obj, os_utime);

shared-bindings/os/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void common_hal_os_rename(const char *old_path, const char *new_path);
4545
void common_hal_os_rmdir(const char *path);
4646
mp_obj_t common_hal_os_stat(const char *path);
4747
mp_obj_t common_hal_os_statvfs(const char *path);
48-
void common_hal_os_utime(const char *path, mp_obj_t time);
48+
void common_hal_os_utime(const char *path, mp_obj_t times);
4949

5050
// Returns true if data was correctly sourced from a true random number generator.
5151
bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length);

shared-module/os/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ mp_obj_t common_hal_os_statvfs(const char *path) {
227227
return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out);
228228
}
229229

230-
void common_hal_os_utime(const char *path, mp_obj_t time) {
230+
void common_hal_os_utime(const char *path, mp_obj_t times) {
231231
mp_obj_t args[2];
232232
mp_vfs_mount_t *vfs = lookup_path(path, &args[0]);
233-
args[1] = time;
233+
args[1] = times;
234234
mp_vfs_proxy_call(vfs, MP_QSTR_utime, 2, args);
235235
}

0 commit comments

Comments
 (0)