private int setFileTime(String path, FileTime aTime, FileTime mTime) { byte[] wpath = WindowsHelpers.toWPath(path); HANDLE handle = wlibc().CreateFileW(wpath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, null, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if (!handle.isValid()) { return -1; // TODO proper error handling } boolean timeSet = wlibc().SetFileTime(handle, null, aTime, mTime); wlibc().CloseHandle(handle); return timeSet ? 0 : -1; }
@Override public int utimes(String path, long[] atimeval, long[] mtimeval) { byte[] wpath = WindowsHelpers.toWPath(path); FileTime aTime = atimeval == null ? null : unixTimeToFileTime(atimeval[0]); FileTime mTime = mtimeval == null ? null : unixTimeToFileTime(mtimeval[0]); if (aTime == null || mTime == null) { FileTime nowFile = unixTimeToFileTime(System.currentTimeMillis() / 1000L); if (aTime == null) aTime = nowFile; if (mTime == null) mTime = nowFile; } HANDLE handle = wlibc().CreateFileW(wpath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, null, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if (!handle.isValid()) { return -1; // TODO proper error handling } boolean timeSet = wlibc().SetFileTime(handle, null, aTime, mTime); wlibc().CloseHandle(handle); return timeSet ? 0 : -1; }
@Override public int utimes(String path, long[] atimeval, long[] mtimeval) { byte[] wpath = WindowsHelpers.toWPath(path); FileTime aTime = atimeval == null ? null : unixTimeToFileTime(atimeval[0]); FileTime mTime = mtimeval == null ? null : unixTimeToFileTime(mtimeval[0]); if (aTime == null || mTime == null) { FileTime nowFile = unixTimeToFileTime(System.currentTimeMillis() / 1000L); if (aTime == null) aTime = nowFile; if (mTime == null) mTime = nowFile; } HANDLE handle = wlibc().CreateFileW(wpath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, null, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if (!handle.isValid()) { return -1; // TODO proper error handling } boolean timeSet = wlibc().SetFileTime(handle, null, aTime, mTime); wlibc().CloseHandle(handle); return timeSet ? 0 : -1; }
@Override public int utimes(String path, long[] atimeval, long[] mtimeval) { byte[] wpath = WindowsHelpers.toWPath(path); FileTime aTime = atimeval == null ? null : unixTimeToFileTime(atimeval[0]); FileTime mTime = mtimeval == null ? null : unixTimeToFileTime(mtimeval[0]); if (aTime == null || mTime == null) { FileTime nowFile = unixTimeToFileTime(System.currentTimeMillis() / 1000L); if (aTime == null) aTime = nowFile; if (mTime == null) mTime = nowFile; } HANDLE handle = wlibc().CreateFileW(wpath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, null, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if (!handle.isValid()) { return -1; // TODO proper error handling } boolean timeSet = wlibc().SetFileTime(handle, null, aTime, mTime); wlibc().CloseHandle(handle); return timeSet ? 0 : -1; }