From 6064265621ff7adadf53951ab26ac29240e346b9 Mon Sep 17 00:00:00 2001 From: "ben%netscape.com" Date: Wed, 26 Jun 2002 05:18:41 +0000 Subject: [PATCH] Fix for 86501 - bookmarks truncated when disk full Make bookmarks check on the success of the file stream write before overwriting the old bookmarks file with the new one. r=darin, sr=brendan --- xpfe/components/bookmarks/src/nsBookmarksService.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/xpfe/components/bookmarks/src/nsBookmarksService.cpp index d3b56c3eb57..2c18e0a77fb 100644 --- a/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -5021,6 +5021,8 @@ nsBookmarksService::WriteBookmarks(nsFileSpec* aBookmarksFile, nsIRDFDataSource* nsFileSpec tempFile(*aBookmarksFile); tempFile.MakeUnique(); + PRBool succeeded = PR_TRUE; + // Scope the stream so that it closes when we're done with it. { nsOutputFileStream strm(tempFile); @@ -5042,13 +5044,13 @@ nsBookmarksService::WriteBookmarks(nsFileSpec* aBookmarksFile, nsIRDFDataSource* // If WriteBookmarksContainer failed for some reason, return that value. // Otherwise, report the status of the stream operation. - rv = NS_FAILED(rv) ? rv : strm.error(); + succeeded = NS_FAILED(rv) ? PR_FALSE : NS_SUCCEEDED(strm.lastWriteStatus()); } // If we wrote to the file successfully (i.e. if the disk wasn't full) // then trash the old bookmarks file and rename the temp file so it takes // its place. - if (NS_SUCCEEDED(rv)) { + if (succeeded) { char* bookmarksFileName = aBookmarksFile->GetLeafName(); aBookmarksFile->Delete(PR_FALSE);