@Jens,
IMO, there is a problem with your patch.
The workflow of your patch is-
1) Write the new contents to a temporary file.
2) Write the new contents to the original file.
3) Delete the file created in step 1.
The problem is, once step 2 is started, the original file is lost. In case of any error, there is no way of recovering the original file.
I've added your modification of delayed delete to my original patch and planning to commit it later this week. This is what my patch looks right now. I need to apply it to the other Save function.
Index: src/sdk/filemanager.cpp
===================================================================
--- src/sdk/filemanager.cpp (revision 5083)
+++ src/sdk/filemanager.cpp (working copy)
@@ -309,19 +309,42 @@
wxString tempName(name + _T(".cbTemp"));
do
{
- wxFile f(tempName, wxFile::write);
- if(!f.IsOpened())
+ if (!wxCopyFile(name, tempName))
+ {
return false;
+ }
+ wxFile f(name, wxFile::write);
+ if (!f.IsOpened())
+ {
+ return false;
+ }
if(WriteWxStringToFile(f, data, encoding, bom) == false)
{
f.Close();
- wxRemoveFile(tempName);
+ // Keep the backup file as the original file has been destroyed
return false;
}
+ else
+ {
+ wxRemoveFile(tempName);
+ }
+
+ f.Close();
+
}while(false);
- return ReplaceFile(name, tempName);
+ if (Manager::IsAppShuttingDown())
+ {
+ // app shut down, forget delayed deletion
+ wxRemoveFile(tempName);
+ }
+ else
+ {
+ // issue a delayed deletion of the back'd up (old) file
+ delayedDeleteThread.Queue(new DelayedDelete(tempName));
+ }
+ return true;
}
bool FileManager::ReplaceFile(const wxString& old_file, const wxString& new_file)
Regards,
Biplab