diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 17:21:07 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 17:21:07 +0000 |
commit | c5866dca4988023e2a538be5c4feeeb52ae5fe80 (patch) | |
tree | 26a9b3b40ab5281e2ece44f6d32b1c09f6cb9b13 /base/file_util_win.cc | |
parent | cfd5c02d5a9b3bd87042b88cdff5d6b5c9e88f3d (diff) | |
download | chromium_src-c5866dca4988023e2a538be5c4feeeb52ae5fe80.zip chromium_src-c5866dca4988023e2a538be5c4feeeb52ae5fe80.tar.gz chromium_src-c5866dca4988023e2a538be5c4feeeb52ae5fe80.tar.bz2 |
Add file_util::ReplaceFile and use it in ImportantFileWriter.
It has more strict semantics than file_util::Move.
http://crbug.com/11585
Review URL: http://codereview.chromium.org/113207
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_win.cc')
-rw-r--r-- | base/file_util_win.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 8964fbf..77247a4 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -116,6 +116,18 @@ bool Move(const FilePath& from_path, const FilePath& to_path) { return false; } +bool ReplaceFile(const FilePath& from_path, const FilePath& to_path) { + // Make sure that the target file exists. + HANDLE target_file = ::CreateFile(to_path.value().c_str(), 0, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, CREATE_NEW, + FILE_ATTRIBUTE_NORMAL, NULL); + if (target_file != INVALID_HANDLE_VALUE) + ::CloseHandle(target_file); + return ::ReplaceFile(to_path.value().c_str(), from_path.value().c_str(), + NULL, 0, NULL, NULL) ? true : false; +} + bool CopyFile(const FilePath& from_path, const FilePath& to_path) { // NOTE: I suspect we could support longer paths, but that would involve // analyzing all our usage of files. |