coreutils
coreutils copied to clipboard
Touch Implementation
Touch utility in V.
dates and times are iso8601. The original date parser in GNU is yacc'd and GPL'ed.
touch.v should be touch.c.v, since it has C. code in it.
renamed touch.v to touch.c.v
You may need to pull & rebase. I took care of a lot of the "noise" from the CI (deprecated functions needed updates, etc.).
Also looks like you'll need to run v fmt -w touch.c.v.
I think that it needs only a windows implementation of fn lutime, and it will be good to merge.
Looks like the Windows equivalent is https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime
Windows C programming is bit out of my wheelhouse. Maybe something like this?
#include <windows.h>
const generic_write = u32(0x40000000)
const open_existing = u32(0x00000003)
const file_attribute_normal = u32(0x00000080)
const null = unsafe { nil }
fn C.CreateFile(&char, u32, u32, voidptr, u32, u32, u32) u32
fn C.SetFileTime(u32, voidptr, voidptr, voidptr) bool
fn lutime(path string, acctime int, modtime int) ! {
f_handle := C.CreateFile(&char(path.str), generic_write, null, open_existing, file_attribute_normal,
u32(0))
if f_handle == 0 {
error('invalid file handle')
}
if !C.SetFileTime(f_handle, null, u64(acctime), u64(modtime)) {
error('unable to set file times')
}
}
We have progress 🥳 :
I need to see what does the gnu coreutils tool do on windows.
The test pass now on the CI, and locally too, when my timezone is set to UTC.
When it is not, the modification times differ:
Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. Therefore, the GetFileTime function may not return the same file time information set using the SetFileTime function. Furthermore, FAT records times on disk in local time. However, NTFS records times on disk in UTC. For more information, see File Times.
I think that is a minor problem, and can be fixed later.
Excellent work @mike-ward . @JalonSolov thanks for the help.
Now that I've gone through a pull request on this project, I know what to do so you guys won't have to fiddle as much with the code.
Thanks for your patience. Working on fmt now.