mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00
Bug 763890 - Add all the old profiles to the same folder when resetting Firefox multiple times, r=bsmedberg
--HG-- extra : rebase_source : 443920ec76501b084c42b548f3cb29d70ce4cec0
This commit is contained in:
parent
5d7a7e1c47
commit
f202608bd9
@ -85,7 +85,7 @@ ProfileResetCleanup(nsIToolkitProfile* aOldProfile)
|
||||
getter_Copies(resetBackupDirectoryName));
|
||||
|
||||
// Get info to copy the old root profile dir to the desktop as a backup.
|
||||
nsCOMPtr<nsIFile> backupDest, uniqueDest;
|
||||
nsCOMPtr<nsIFile> backupDest, containerDest, profileDest;
|
||||
rv = NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(backupDest));
|
||||
if (NS_FAILED(rv)) {
|
||||
// Fall back to the home directory if the desktop is not available.
|
||||
@ -93,17 +93,38 @@ ProfileResetCleanup(nsIToolkitProfile* aOldProfile)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
// Try to get a unique backup directory name.
|
||||
backupDest->Clone(getter_AddRefs(uniqueDest));
|
||||
uniqueDest->Append(resetBackupDirectoryName);
|
||||
rv = uniqueDest->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700);
|
||||
// Try to create a directory for all the backups
|
||||
backupDest->Clone(getter_AddRefs(containerDest));
|
||||
containerDest->Append(resetBackupDirectoryName);
|
||||
rv = containerDest->Create(nsIFile::DIRECTORY_TYPE, 0700);
|
||||
// It's OK if it already exists, if and only if it is a directory
|
||||
if (rv == NS_ERROR_FILE_ALREADY_EXISTS) {
|
||||
bool containerIsDir;
|
||||
rv = containerDest->IsDirectory(&containerIsDir);
|
||||
if (NS_FAILED(rv) || !containerIsDir) {
|
||||
return rv;
|
||||
}
|
||||
} else if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Get the name of the profile
|
||||
nsAutoString leafName;
|
||||
rv = profileDir->GetLeafName(leafName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString leafName;
|
||||
rv = uniqueDest->GetLeafName(leafName);
|
||||
// Try to create a unique directory for the profile:
|
||||
containerDest->Clone(getter_AddRefs(profileDest));
|
||||
profileDest->Append(leafName);
|
||||
rv = profileDest->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the unique profile name
|
||||
rv = profileDest->GetLeafName(leafName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Delete the empty directory that CreateUnique just created.
|
||||
rv = uniqueDest->Remove(false);
|
||||
rv = profileDest->Remove(false);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Show a progress window while the cleanup happens since the disk I/O can take time.
|
||||
@ -128,7 +149,7 @@ ProfileResetCleanup(nsIToolkitProfile* aOldProfile)
|
||||
rv = tm->NewThread(0, 0, getter_AddRefs(cleanupThread));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIRunnable> runnable = new ProfileResetCleanupAsyncTask(profileDir, profileLocalDir,
|
||||
backupDest, leafName);
|
||||
containerDest, leafName);
|
||||
cleanupThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
|
||||
// The result callback will shut down the worker thread.
|
||||
|
||||
@ -145,7 +166,7 @@ ProfileResetCleanup(nsIToolkitProfile* aOldProfile)
|
||||
// Close the progress window now that the cleanup thread is done.
|
||||
progressWindow->Close();
|
||||
|
||||
// Delete the old profile from profiles.ini. The folder was already deleted above.
|
||||
// Delete the old profile from profiles.ini. The folder was already deleted by the thread above.
|
||||
rv = aOldProfile->Remove(false);
|
||||
if (NS_FAILED(rv)) NS_WARNING("Could not remove the profile");
|
||||
|
||||
|
@ -38,10 +38,10 @@ class ProfileResetCleanupAsyncTask : public nsRunnable
|
||||
{
|
||||
public:
|
||||
ProfileResetCleanupAsyncTask(nsIFile* aProfileDir, nsIFile* aProfileLocalDir,
|
||||
nsIFile* aDesktop, const nsAString &aLeafName)
|
||||
nsIFile* aTargetDir, const nsAString &aLeafName)
|
||||
: mProfileDir(aProfileDir)
|
||||
, mProfileLocalDir(aProfileLocalDir)
|
||||
, mDesktop(aDesktop)
|
||||
, mTargetDir(aTargetDir)
|
||||
, mLeafName(aLeafName)
|
||||
{ }
|
||||
|
||||
@ -51,7 +51,7 @@ public:
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
// Copy to the destination then delete the profile. A move doesn't follow links.
|
||||
nsresult rv = mProfileDir->CopyToFollowingLinks(mDesktop, mLeafName);
|
||||
nsresult rv = mProfileDir->CopyToFollowingLinks(mTargetDir, mLeafName);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = mProfileDir->Remove(true);
|
||||
else
|
||||
@ -75,6 +75,6 @@ public:
|
||||
private:
|
||||
nsCOMPtr<nsIFile> mProfileDir;
|
||||
nsCOMPtr<nsIFile> mProfileLocalDir;
|
||||
nsCOMPtr<nsIFile> mDesktop;
|
||||
nsCOMPtr<nsIFile> mTargetDir;
|
||||
nsAutoString mLeafName;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user