summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authorskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 17:00:09 +0000
committerskerner@chromium.org <skerner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-30 17:00:09 +0000
commitb0b3abd98a59384a83349c83a5ef9b14851816da (patch)
tree790628087c773280456dffae7cfb0ea8f744649f /base/file_util_posix.cc
parentec2717e405abc8f618133fe3c9f5051fff224e71 (diff)
downloadchromium_src-b0b3abd98a59384a83349c83a5ef9b14851816da.zip
chromium_src-b0b3abd98a59384a83349c83a5ef9b14851816da.tar.gz
chromium_src-b0b3abd98a59384a83349c83a5ef9b14851816da.tar.bz2
Unpack extensions inside chrome's profile directory.
Other users of the temp directory will be altered in a subsequent CL. BUG=13044 TEST=SandboxedExtensionUnpackerTest.*, ScopedTempDir.UniqueTempDirUnderPath, FileUtilTest.CreateNewTempDirInDirTest, manual testing on win, linux, mac. Review URL: http://codereview.chromium.org/1582022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc37
1 files changed, 28 insertions, 9 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 4d4e572..d9cbe09 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -401,22 +401,41 @@ bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) {
return ((fd >= 0) && !close(fd));
}
-bool CreateNewTempDirectory(const FilePath::StringType& prefix,
- FilePath* new_temp_path) {
- FilePath tmpdir;
- if (!GetTempDir(&tmpdir))
- return false;
- tmpdir = tmpdir.Append(kTempFileName);
- std::string tmpdir_string = tmpdir.value();
+static bool CreateTemporaryDirInDirImpl(const FilePath& base_dir,
+ const FilePath::StringType& name_tmpl,
+ FilePath* new_dir) {
+ CHECK(name_tmpl.find("XXXXXX") != FilePath::StringType::npos)
+ << "Directory name template must contain \"XXXXXX\".";
+
+ FilePath sub_dir = base_dir.Append(name_tmpl);
+ std::string sub_dir_string = sub_dir.value();
+
// this should be OK since mkdtemp just replaces characters in place
- char* buffer = const_cast<char*>(tmpdir_string.c_str());
+ char* buffer = const_cast<char*>(sub_dir_string.c_str());
char* dtemp = mkdtemp(buffer);
if (!dtemp)
return false;
- *new_temp_path = FilePath(dtemp);
+ *new_dir = FilePath(dtemp);
return true;
}
+bool CreateTemporaryDirInDir(const FilePath& base_dir,
+ const FilePath::StringType& prefix,
+ FilePath* new_dir) {
+ FilePath::StringType mkdtemp_template = prefix;
+ mkdtemp_template.append(FILE_PATH_LITERAL("XXXXXX"));
+ return CreateTemporaryDirInDirImpl(base_dir, mkdtemp_template, new_dir);
+}
+
+bool CreateNewTempDirectory(const FilePath::StringType& prefix,
+ FilePath* new_temp_path) {
+ FilePath tmpdir;
+ if (!GetTempDir(&tmpdir))
+ return false;
+
+ return CreateTemporaryDirInDirImpl(tmpdir, kTempFileName, new_temp_path);
+}
+
bool CreateDirectory(const FilePath& full_path) {
std::vector<FilePath> subpaths;