summaryrefslogtreecommitdiffstats
path: root/base/scoped_temp_dir.cc
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-23 10:06:47 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-23 10:06:47 +0000
commit9fefee68b27573a37c00bd428d62b72eecbc8993 (patch)
treeec3769c452ad84dc1f347b8b1d116d1e6979b5b6 /base/scoped_temp_dir.cc
parent27c8112304862f884ad63f90b192a86866d4deda (diff)
downloadchromium_src-9fefee68b27573a37c00bd428d62b72eecbc8993.zip
chromium_src-9fefee68b27573a37c00bd428d62b72eecbc8993.tar.gz
chromium_src-9fefee68b27573a37c00bd428d62b72eecbc8993.tar.bz2
ScopedTempDir does not allow multiple Create* or Set calls without intervening Delete/Take calls.
BUG=None TEST=base_unittests --gtest_filter="*ScopedTempDir*", all other tests pass. Review URL: http://codereview.chromium.org/3980006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/scoped_temp_dir.cc')
-rw-r--r--base/scoped_temp_dir.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/base/scoped_temp_dir.cc b/base/scoped_temp_dir.cc
index a510ddf..5cd13b4 100644
--- a/base/scoped_temp_dir.cc
+++ b/base/scoped_temp_dir.cc
@@ -15,6 +15,9 @@ ScopedTempDir::~ScopedTempDir() {
}
bool ScopedTempDir::CreateUniqueTempDir() {
+ if (!path_.empty())
+ return false;
+
// This "scoped_dir" prefix is only used on Windows and serves as a template
// for the unique name.
if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"),
@@ -25,7 +28,10 @@ bool ScopedTempDir::CreateUniqueTempDir() {
}
bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) {
- // If |path| does not exist, create it.
+ if (!path_.empty())
+ return false;
+
+ // If |base_path| does not exist, create it.
if (!file_util::CreateDirectory(base_path))
return false;
@@ -33,18 +39,20 @@ bool ScopedTempDir::CreateUniqueTempDirUnderPath(const FilePath& base_path) {
if (!file_util::CreateTemporaryDirInDir(
base_path,
FILE_PATH_LITERAL("scoped_dir_"),
- &path_)) {
+ &path_))
return false;
- }
+
return true;
}
bool ScopedTempDir::Set(const FilePath& path) {
- DCHECK(path_.empty());
+ if (!path_.empty())
+ return false;
+
if (!file_util::DirectoryExists(path) &&
- !file_util::CreateDirectory(path)) {
+ !file_util::CreateDirectory(path))
return false;
- }
+
path_ = path;
return true;
}