Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32/File.cpp: utime: fallback to 01/01/1980 00:00:00 if the date is too low #14019

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,23 @@ bool fs::utime(const std::string& path, s64 atime, s64 mtime)
FILETIME _mtime = from_time(mtime);
if (!SetFileTime(handle, nullptr, &_atime, &_mtime))
{
g_tls_error = to_error(GetLastError());
const DWORD last_error = GetLastError();
g_tls_error = to_error(last_error);

// Some filesystems fail to set a date lower than 01/01/1980 00:00:00
if (last_error == ERROR_INVALID_PARAMETER && (atime < 315532800 || mtime < 315532800))
{
// Try again with 01/01/1980 00:00:00
_atime = from_time(std::max<s64>(atime, 315532800));
_mtime = from_time(std::max<s64>(mtime, 315532800));

if (SetFileTime(handle, nullptr, &_atime, &_mtime))
{
CloseHandle(handle);
return true;
}
}

CloseHandle(handle);
return false;
}
Expand Down