Skip to content

Commit

Permalink
Flush .aup before writing .au; no redundant out-of-space messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Oct 25, 2017
1 parent 7eeb883 commit 58f07d2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3873,15 +3873,24 @@ bool AudacityProject::Save(bool overwrite /* = true */ ,
// Write the .aup now, before DirManager::SetProject,
// because it's easier to clean up the effects of successful write of .aup
// followed by failed SetProject, than the other way about.
// And that cleanup is done by the destructor of saveFile, if Commit() is
// And that cleanup is done by the destructor of saveFile, if PostCommit() is
// not done.
// (SetProject, when it fails, cleans itself up.)
XMLFileWriter saveFile{ mFileName, _("Error Saving Project") };
success = GuardedCall< bool >( [&] {
WriteXMLHeader(saveFile);
WriteXML(saveFile, bWantSaveCompressed);
return true;
} );
WriteXMLHeader(saveFile);
WriteXML(saveFile, bWantSaveCompressed);
// Flushes files, forcing space exhaustion errors before trying
// SetProject():
saveFile.PreCommit();
return true;
},
MakeSimpleGuard(false),
// Suppress the usual error dialog for failed write,
// which is redundant here:
[](void*){}
);

if (!success)
return false;

Expand Down Expand Up @@ -3920,9 +3929,14 @@ bool AudacityProject::Save(bool overwrite /* = true */ ,

// Commit the writing of the .aup only now, after we know that the _data
// folder also saved with no problems.
// Error recovery in case this fails might not be correct -- there is no
// provision to undo the effects of SetProject -- but it is very unlikely
// that this will happen: only renaming and removing of files happens,
// not writes that might exhaust space. So DO give a second dialog in
// case the unusual happens.
success = success && GuardedCall< bool >( [&] {
saveFile.Commit();
return true;
saveFile.PostCommit();
return true;
} );

if (!success)
Expand Down
13 changes: 12 additions & 1 deletion src/xml/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,25 @@ XMLFileWriter::~XMLFileWriter()

void XMLFileWriter::Commit()
// may throw
{
PreCommit();
PostCommit();
}

void XMLFileWriter::PreCommit()
// may throw
{
while (mTagstack.GetCount()) {
EndTag(mTagstack[0]);
}

auto tempPath = GetName();
CloseWithoutEndingTags();
}

void XMLFileWriter::PostCommit()
// may throw
{
auto tempPath = GetName();
if (mKeepBackup) {
if (! mBackupFile.Close() ||
! wxRenameFile( mOutputPath, mBackupName ) )
Expand Down
8 changes: 8 additions & 0 deletions src/xml/XMLWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,16 @@ class AUDACITY_DLL_API XMLFileWriter final : private wxFFile, public XMLWriter {
/// Close all tags and then close the file.
/// Might throw. If not, then create
/// or modify the file at the output path.
/// Composed of two steps, PreCommit() and PostCommit()
void Commit();

/// Does the part of Commit that might fail because of exhaustion of space
void PreCommit();

/// Does other parts of Commit that are not likely to fail for exhaustion
/// of space, but might for other reasons
void PostCommit();

/// Write to file. Might throw.
void Write(const wxString &data) override;

Expand Down

0 comments on commit 58f07d2

Please sign in to comment.