Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2168)

Unified Diff: chrome/installer/util/installer_state.cc

Issue 11417038: IsFileInUse should return false when the file doesn't exist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync past r168281 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/util/installer_state.cc
diff --git a/chrome/installer/util/installer_state.cc b/chrome/installer/util/installer_state.cc
index b7ab42ba04e7635808035d563462fb39292e7a5c..8d188e2da7d75cd286d23e01c4c68d3cec750135 100644
--- a/chrome/installer/util/installer_state.cc
+++ b/chrome/installer/util/installer_state.cc
@@ -16,7 +16,6 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
-#include "base/win/scoped_handle.h"
#include "chrome/installer/util/delete_tree_work_item.h"
#include "chrome/installer/util/helper.h"
#include "chrome/installer/util/install_util.h"
@@ -582,9 +581,14 @@ FilePath InstallerState::GetInstallerDirectory(const Version& version) const {
bool InstallerState::IsFileInUse(const FilePath& file) {
// Call CreateFile with a share mode of 0 which should cause this to fail
// with ERROR_SHARING_VIOLATION if the file exists and is in-use.
- return !base::win::ScopedHandle(CreateFile(file.value().c_str(),
- GENERIC_WRITE, 0, NULL,
- OPEN_EXISTING, 0, 0)).IsValid();
+ HANDLE file_handle = CreateFile(file.value().c_str(), GENERIC_WRITE, 0, NULL,
+ OPEN_EXISTING, 0, 0);
+ bool in_use = false;
+ if (file_handle != INVALID_HANDLE_VALUE)
+ CloseHandle(file_handle);
+ else if (GetLastError() != ERROR_FILE_NOT_FOUND)
+ in_use = true;
+ return in_use;
}
« no previous file with comments | « no previous file | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698