Delete the installation folder after deleting its contents.


R=gab
BUG=138615
TEST=setup.exe --multi-install --chrome; setup.exe --multi-install --uninstall --chrome; (check 'Delete user profile' option); verify C:/Users/<you>/AppData/Local/Google/Chrome is gone.

Review URL: https://chromiumcodereview.appspot.com/10832210

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151354 0039d316-1c4b-4281-b951-d872f2087c98
parent 052125aa
...@@ -318,25 +318,25 @@ bool ScheduleParentAndGrandparentForDeletion(const FilePath& path) { ...@@ -318,25 +318,25 @@ bool ScheduleParentAndGrandparentForDeletion(const FilePath& path) {
return ret; return ret;
} }
// Deletes empty parent & empty grandparent dir of given path. enum DeleteResult {
bool DeleteEmptyParentDir(const FilePath& path) { DELETE_SUCCEEDED,
bool ret = true; DELETE_NOT_EMPTY,
FilePath parent_dir = path.DirName(); DELETE_FAILED,
if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { DELETE_REQUIRES_REBOOT,
if (!file_util::Delete(parent_dir, true)) { };
ret = false;
LOG(ERROR) << "Failed to delete folder: " << parent_dir.value();
}
parent_dir = parent_dir.DirName(); // Deletes the given directory if it is empty. Returns DELETE_SUCCEEDED if the
if (!parent_dir.empty() && file_util::IsDirectoryEmpty(parent_dir)) { // directory is deleted, DELETE_NOT_EMPTY if it is not empty, and DELETE_FAILED
if (!file_util::Delete(parent_dir, true)) { // otherwise.
ret = false; DeleteResult DeleteEmptyDir(const FilePath& path) {
LOG(ERROR) << "Failed to delete folder: " << parent_dir.value(); if (!file_util::IsDirectoryEmpty(path))
} return DELETE_NOT_EMPTY;
}
} if (file_util::Delete(path, true))
return ret; return DELETE_SUCCEEDED;
LOG(ERROR) << "Failed to delete folder: " << path.value();
return DELETE_FAILED;
} }
void GetLocalStateFolders(const Product& product, void GetLocalStateFolders(const Product& product,
...@@ -367,12 +367,6 @@ FilePath BackupLocalStateFile( ...@@ -367,12 +367,6 @@ FilePath BackupLocalStateFile(
return backup; return backup;
} }
enum DeleteResult {
DELETE_SUCCEEDED,
DELETE_FAILED,
DELETE_REQUIRES_REBOOT,
};
// Deletes all user data directories for a product. // Deletes all user data directories for a product.
DeleteResult DeleteLocalState(const std::vector<FilePath>& local_state_folders, DeleteResult DeleteLocalState(const std::vector<FilePath>& local_state_folders,
bool schedule_on_failure) { bool schedule_on_failure) {
...@@ -398,7 +392,13 @@ DeleteResult DeleteLocalState(const std::vector<FilePath>& local_state_folders, ...@@ -398,7 +392,13 @@ DeleteResult DeleteLocalState(const std::vector<FilePath>& local_state_folders,
if (result == DELETE_REQUIRES_REBOOT) { if (result == DELETE_REQUIRES_REBOOT) {
ScheduleParentAndGrandparentForDeletion(local_state_folders[0]); ScheduleParentAndGrandparentForDeletion(local_state_folders[0]);
} else { } else {
DeleteEmptyParentDir(local_state_folders[0]); const FilePath user_data_dir(local_state_folders[0].DirName());
if (!user_data_dir.empty() &&
DeleteEmptyDir(user_data_dir) == DELETE_SUCCEEDED) {
const FilePath product_dir(user_data_dir.DirName());
if (!product_dir.empty())
DeleteEmptyDir(product_dir);
}
} }
return result; return result;
...@@ -428,6 +428,27 @@ bool MoveSetupOutOfInstallFolder(const InstallerState& installer_state, ...@@ -428,6 +428,27 @@ bool MoveSetupOutOfInstallFolder(const InstallerState& installer_state,
return ret; return ret;
} }
DeleteResult DeleteApplicationProductAndVendorDirectories(
const FilePath& application_directory) {
DeleteResult result(DeleteEmptyDir(application_directory));
if (result == DELETE_SUCCEEDED) {
// Now check and delete if the parent directories are empty
// For example Google\Chrome or Chromium
const FilePath product_directory(application_directory.DirName());
if (!product_directory.empty()) {
result = DeleteEmptyDir(product_directory);
if (result == DELETE_SUCCEEDED) {
const FilePath vendor_directory(product_directory.DirName());
if (!vendor_directory.empty())
result = DeleteEmptyDir(vendor_directory);
}
}
}
if (result == DELETE_NOT_EMPTY)
result = DELETE_SUCCEEDED;
return result;
}
DeleteResult DeleteAppHostFilesAndFolders(const InstallerState& installer_state, DeleteResult DeleteAppHostFilesAndFolders(const InstallerState& installer_state,
const Version& installed_version) { const Version& installed_version) {
const FilePath& target_path = installer_state.target_path(); const FilePath& target_path = installer_state.target_path();
...@@ -446,7 +467,7 @@ DeleteResult DeleteAppHostFilesAndFolders(const InstallerState& installer_state, ...@@ -446,7 +467,7 @@ DeleteResult DeleteAppHostFilesAndFolders(const InstallerState& installer_state,
result = DELETE_FAILED; result = DELETE_FAILED;
LOG(ERROR) << "Failed to delete path: " << app_host_exe.value(); LOG(ERROR) << "Failed to delete path: " << app_host_exe.value();
} else { } else {
DeleteEmptyParentDir(target_path); result = DeleteApplicationProductAndVendorDirectories(target_path);
} }
return result; return result;
...@@ -475,7 +496,7 @@ DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state, ...@@ -475,7 +496,7 @@ DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state,
if (to_delete.BaseName().value() == installer::kChromeAppHostExe) if (to_delete.BaseName().value() == installer::kChromeAppHostExe)
continue; continue;
VLOG(1) << "Deleting install path " << target_path.value(); VLOG(1) << "Deleting install path " << to_delete.value();
if (!file_util::Delete(to_delete, true)) { if (!file_util::Delete(to_delete, true)) {
LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value(); LOG(ERROR) << "Failed to delete path (1st try): " << to_delete.value();
if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) { if (installer_state.FindProduct(BrowserDistribution::CHROME_FRAME)) {
...@@ -504,14 +525,15 @@ DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state, ...@@ -504,14 +525,15 @@ DeleteResult DeleteChromeFilesAndFolders(const InstallerState& installer_state,
} }
if (result == DELETE_REQUIRES_REBOOT) { if (result == DELETE_REQUIRES_REBOOT) {
// Delete the Application directory at reboot if empty.
ScheduleFileSystemEntityForDeletion(target_path.value().c_str());
// If we need a reboot to continue, schedule the parent directories for // If we need a reboot to continue, schedule the parent directories for
// deletion unconditionally. If they are not empty, the session manager // deletion unconditionally. If they are not empty, the session manager
// will not delete them on reboot. // will not delete them on reboot.
ScheduleParentAndGrandparentForDeletion(target_path); ScheduleParentAndGrandparentForDeletion(target_path);
} else { } else {
// Now check and delete if the parent directories are empty result = DeleteApplicationProductAndVendorDirectories(target_path);
// For example Google\Chrome or Chromium
DeleteEmptyParentDir(target_path);
} }
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment