Skip to content

Commit

Permalink
Delete the Google directory if it is empty.
Browse files Browse the repository at this point in the history
This CL does a best-effort attempt to delete the company directory if it is empty. The company directory is `%LocalAppData%/Google` or `%ProgramFiles%/Google`.
  • Loading branch information
sorinj committed May 31, 2023
1 parent 405e03e commit 8fa5322
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions omaha/common/config_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,24 @@ CString ConfigManager::GetMachineGoopdateInstallDir() const {
return path;
}

CString ConfigManager::GetUserCompanyDir() const {
CString path;
VERIFY_SUCCEEDED(GetDir32(CSIDL_LOCAL_APPDATA,
CString(OMAHA_REL_COMPANY_DIR),
false,
&path));
return path;
}

CString ConfigManager::GetMachineCompanyDir() const {
CString path;
VERIFY_SUCCEEDED(GetDir32(CSIDL_PROGRAM_FILES,
CString(OMAHA_REL_COMPANY_DIR),
false,
&path));
return path;
}

CString ConfigManager::GetTempDir() const {
return ::IsUserAnAdmin() ? GetSecureSystemTempDir() :
app_util::GetTempDirForImpersonatedOrCurrentUser();
Expand Down
6 changes: 6 additions & 0 deletions omaha/common/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ class ConfigManager {
// %ProgramFiles%/Google/Update
CString GetMachineGoopdateInstallDir() const;

// Gets the Google company directory. Does not create the directory if it does
// not already exist.
// `%LocalAppData%/Google` or `%ProgramFiles%/Google`.
CString GetUserCompanyDir() const;
CString GetMachineCompanyDir() const;

// Creates and returns a secure directory, %ProgramFiles%/Google/Temp, if
// running as Admin. Otherwise, returns the %TMP% for the impersonated or
// current user.
Expand Down
14 changes: 14 additions & 0 deletions omaha/setup/setup_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ void SetupFiles::Uninstall() {
SETUP_LOG(LE, (_T("[DeleteDirectory failed][%s][0x%08x]"),
install_dir, hr));
}

// Best-effort attempt to delete the company directory if it is empty.
CString company_dir(
is_machine_ ? ConfigManager::Instance()->GetMachineCompanyDir() :
ConfigManager::Instance()->GetUserCompanyDir());
if (!File::IsDirectory(company_dir) || !::PathIsDirectoryEmpty(company_dir)) {
return;
}

// `::RemoveDirectory` deletes an existing empty directory.
if (!::RemoveDirectory(company_dir)) {
hr = HRESULTFromLastError();
SETUP_LOG(LE, (_T("[::RemoveDirectory failed][%s][%#x]"), company_dir, hr));
}
}

HRESULT SetupFiles::CopyShell() {
Expand Down

0 comments on commit 8fa5322

Please sign in to comment.