Skip to content

Commit

Permalink
Last accessed timestamp is modified when we reset the source file's a…
Browse files Browse the repository at this point in the history
…rchive attribute.

To prevent this change, cryptsync was restoring the source file's timestamp after the attribut change. This trigger Window to notify of a source file change.

The benefit of preseving the source file's access time is limited so the code was removed.

Furthermore, the last access time of the file is recorded in the .7z file. Since the 7z library does not call SetFileTime after the source file is open with 0xFFFFFFFF, the timestamp recorded is the time cryptsync read the file.

Also, when decrypting the file either with 7Zip or cryptsync, the creation and last access time are those of the extraction.

The extra Wndows change notification has no functional impact.
  • Loading branch information
dansyl1 committed Aug 9, 2024
1 parent c3b6d5b commit 2445a76
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions src/FolderSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,34 +1634,7 @@ void CFolderSync::AdjustFileAttributes(const std::wstring& fName, DWORD dwFileAt
}
else
{
bRet = false;
// Use FILE_WRITE_ATTRIBUTES below to prevent sharing violation if working on
// file open by another application
CAutoFile hFile = CreateFile(fName.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
error = ::GetLastError();
if (hFile.IsValid())
{
retry = 5;
do
{
if (m_pProgDlg && m_pProgDlg->HasUserCancelled())
break;
bRet = !!SetFileTime(hFile, &fData.ftCreationTime, &fData.ftLastAccessTime, &fData.ftLastWriteTime);
error = ::GetLastError();
if (!bRet)
Sleep(200);
} while (!bRet && (retry-- > 0));
hFile.CloseHandle();
}
if (!bRet)
{
_com_error comError(error);
LPCTSTR comErrorText = comError.ErrorMessage();
CCircularLog::Instance()(_T("INFO: failed to set file time on %s while adjusting its attributes (%s)"), fName.c_str(), comErrorText);
CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": Unable to set file time on %s (%s)\n"), fName.c_str(), comErrorText);
}
else
CCircularLog::Instance()(_T("INFO: successfully adjusted attribute on %s"), fName.c_str());
CCircularLog::Instance()(_T("INFO: successfully adjusted attribute on %s"), fName.c_str());
}
}

Expand Down

0 comments on commit 2445a76

Please sign in to comment.