Corrupt prefs.js file not removed if backup file (invalidprefs.js) exists. b=495735 r=benjamin a1.9.0.16=dveditz
git-svn-id: svn://10.0.0.236/trunk@258961 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
1b1e85dcaa
commit
64d8d66e6f
@ -21,6 +21,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
* Mats Palmgren <matspal@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -85,10 +86,6 @@ static nsresult pref_InitInitialObjects(void);
|
||||
*/
|
||||
|
||||
nsPrefService::nsPrefService()
|
||||
: mDontWriteUserPrefs(PR_FALSE)
|
||||
#if MOZ_PROFILESHARING
|
||||
, mDontWriteSharedUserPrefs(PR_FALSE)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
@ -367,10 +364,22 @@ nsresult nsPrefService::UseUserPrefFile()
|
||||
nsresult nsPrefService::MakeBackupPrefFile(nsIFile *aFile)
|
||||
{
|
||||
// Example: this copies "prefs.js" to "Invalidprefs.js" in the same directory.
|
||||
// "Invalidprefs.js" is removed if it exists, prior to making the copy.
|
||||
nsAutoString newFilename;
|
||||
nsresult rv = aFile->GetLeafName(newFilename);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
newFilename.Insert(NS_LITERAL_STRING("Invalid"), 0);
|
||||
nsCOMPtr<nsIFile> newFile;
|
||||
rv = aFile->GetParent(getter_AddRefs(newFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = newFile->Append(newFilename);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
PRBool exists = PR_FALSE;
|
||||
newFile->Exists(&exists);
|
||||
if (exists) {
|
||||
rv = newFile->Remove(PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
rv = aFile->CopyTo(nsnull, newFilename);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return rv;
|
||||
@ -395,7 +404,10 @@ nsresult nsPrefService::ReadAndOwnUserPrefFile(nsIFile *aFile)
|
||||
if (exists) {
|
||||
rv = openPrefFile(mCurrentFile);
|
||||
if (NS_FAILED(rv)) {
|
||||
mDontWriteUserPrefs = NS_FAILED(MakeBackupPrefFile(mCurrentFile));
|
||||
// Save a backup copy of the current (invalid) prefs file, since all prefs
|
||||
// from the error line to the end of the file will be lost (bug 361102).
|
||||
// TODO we should notify the user about it (bug 523725).
|
||||
MakeBackupPrefFile(mCurrentFile);
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_FILE_NOT_FOUND;
|
||||
@ -424,7 +436,10 @@ nsresult nsPrefService::ReadAndOwnSharedUserPrefFile(nsIFile *aFile)
|
||||
|
||||
nsresult rv = openPrefFile(mCurrentSharedFile);
|
||||
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
|
||||
mDontWriteSharedUserPrefs = NS_FAILED(MakeBackupPrefFile(mCurrentSharedFile));
|
||||
// Save a backup copy of the current (invalid) prefs file, since all prefs
|
||||
// from the error line to the end of the file will be lost (bug 361102).
|
||||
// TODO we should notify the user about it (bug 523725).
|
||||
MakeBackupPrefFile(mCurrentSharedFile);
|
||||
}
|
||||
|
||||
#ifdef MOZ_PROFILESHARING
|
||||
@ -494,16 +509,6 @@ nsresult nsPrefService::WritePrefFile(nsIFile* aFile)
|
||||
if (!gHashTable.ops)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// Don't save user prefs if there was an error reading them and we failed
|
||||
// to make a backup copy, since all prefs from the error line to the end of
|
||||
// the file would be lost (bug 361102).
|
||||
if (mDontWriteUserPrefs && aFile == mCurrentFile)
|
||||
return NS_OK;
|
||||
#if MOZ_PROFILESHARING
|
||||
if (mDontWriteSharedUserPrefs && aFile == mCurrentSharedFile)
|
||||
return NS_OK;
|
||||
#endif
|
||||
|
||||
// execute a "safe" save by saving through a tempfile
|
||||
rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(outStreamSink),
|
||||
aFile,
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Brian Nesse <bnesse@netscape.com>
|
||||
* Mats Palmgren <matspal@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -79,11 +80,9 @@ protected:
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIPrefBranch2> mRootBranch;
|
||||
nsCOMPtr<nsIFile> mCurrentFile;
|
||||
PRPackedBool mDontWriteUserPrefs;
|
||||
nsCOMPtr<nsIFile> mCurrentFile;
|
||||
#if MOZ_PROFILESHARING
|
||||
nsCOMPtr<nsIFile> mCurrentSharedFile;
|
||||
PRPackedBool mDontWriteSharedUserPrefs;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user