mirror of https://github.com/odrling/Aegisub
Retry commits of file writes for up to a second to work around AV scanning
Poorly-written antivirus software briefly lock newly written files to scan them for viruses, which makes the rename from the temp file to actual file fail. Work around this by retrying the rename up to ten times. Closes #1618.
This commit is contained in:
parent
38dedfe1d9
commit
69b05d49de
|
@ -97,7 +97,22 @@ Save::Save(const std::string& file, bool binary)
|
|||
|
||||
Save::~Save() {
|
||||
delete fp;
|
||||
#ifndef _WIN32
|
||||
util::Rename(tmp_name, file_name);
|
||||
#else
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
try {
|
||||
util::Rename(tmp_name, file_name);
|
||||
return;
|
||||
}
|
||||
catch (agi::FileNotAccessibleError const&) {
|
||||
// Retry up to ten times in case it's just locked by a poorly-written antivirus scanner
|
||||
if (i == 9)
|
||||
throw;
|
||||
Sleep(100);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::ofstream& Save::Get() {
|
||||
|
|
Loading…
Reference in New Issue