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

Unified Diff: base/file_util_posix.cc

Issue 1582022: Unpack extensions inside chrome's directory. (Closed)
Patch Set: Final rebase. Created 10 years, 8 months 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 | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 4d4e5721b47edf9a3cda00285bb5a980c0fad597..d9cbe0945e75fe3be45dd380affcf445c0051a25 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;
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698