summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-01 23:07:36 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-01 23:07:36 +0000
commit5553d5bcd8c1f0d90d74a2a52a4c9af51d730d01 (patch)
treef719fa0c440cb3492ccf9c9a2739afd5af5eace6 /base/file_util_posix.cc
parent10c1234fe5e6b43cd9f2f03f91da2c96083c7643 (diff)
downloadchromium_src-5553d5bcd8c1f0d90d74a2a52a4c9af51d730d01.zip
chromium_src-5553d5bcd8c1f0d90d74a2a52a4c9af51d730d01.tar.gz
chromium_src-5553d5bcd8c1f0d90d74a2a52a4c9af51d730d01.tar.bz2
Move DeleteAfterReboot, Move, and ReplaceFile to base namespace
Rename ReplaceFileAndGetError (only used once) to ReplaceFile (used 5 times) and have each of those callers specify NULL for the output error if they don't care. Remove InsertBeforeExtension from file_util.cc which seems to be unused. BUG= Review URL: https://codereview.chromium.org/18383003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc83
1 files changed, 42 insertions, 41 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index afb34b4..899bdb9 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -65,28 +65,28 @@ namespace {
#if defined(OS_BSD) || defined(OS_MACOSX)
typedef struct stat stat_wrapper_t;
static int CallStat(const char *path, stat_wrapper_t *sb) {
- base::ThreadRestrictions::AssertIOAllowed();
+ ThreadRestrictions::AssertIOAllowed();
return stat(path, sb);
}
static int CallLstat(const char *path, stat_wrapper_t *sb) {
- base::ThreadRestrictions::AssertIOAllowed();
+ ThreadRestrictions::AssertIOAllowed();
return lstat(path, sb);
}
#else
typedef struct stat64 stat_wrapper_t;
static int CallStat(const char *path, stat_wrapper_t *sb) {
- base::ThreadRestrictions::AssertIOAllowed();
+ ThreadRestrictions::AssertIOAllowed();
return stat64(path, sb);
}
static int CallLstat(const char *path, stat_wrapper_t *sb) {
- base::ThreadRestrictions::AssertIOAllowed();
+ ThreadRestrictions::AssertIOAllowed();
return lstat64(path, sb);
}
#endif
// Helper for NormalizeFilePath(), defined below.
bool RealPath(const FilePath& path, FilePath* real_path) {
- base::ThreadRestrictions::AssertIOAllowed(); // For realpath().
+ ThreadRestrictions::AssertIOAllowed(); // For realpath().
FilePath::CharType buf[PATH_MAX];
if (!realpath(path.value().c_str(), buf))
return false;
@@ -134,6 +134,18 @@ bool VerifySpecificPathControlledByUser(const FilePath& path,
return true;
}
+std::string TempFileName() {
+#if defined(OS_MACOSX)
+ return StringPrintf(".%s.XXXXXX", base::mac::BaseBundleID());
+#endif
+
+#if defined(GOOGLE_CHROME_BUILD)
+ return std::string(".com.google.Chrome.XXXXXX");
+#else
+ return std::string(".org.chromium.Chromium.XXXXXX");
+#endif
+}
+
} // namespace
FilePath MakeAbsoluteFilePath(const FilePath& input) {
@@ -185,35 +197,8 @@ bool Delete(const FilePath& path, bool recursive) {
return success;
}
-} // namespace base
-
-// -----------------------------------------------------------------------------
-
-namespace file_util {
-
-using base::stat_wrapper_t;
-using base::CallStat;
-using base::CallLstat;
-using base::FileEnumerator;
-using base::FilePath;
-using base::MakeAbsoluteFilePath;
-using base::RealPath;
-using base::VerifySpecificPathControlledByUser;
-
-static std::string TempFileName() {
-#if defined(OS_MACOSX)
- return base::StringPrintf(".%s.XXXXXX", base::mac::BaseBundleID());
-#endif
-
-#if defined(GOOGLE_CHROME_BUILD)
- return std::string(".com.google.Chrome.XXXXXX");
-#else
- return std::string(".org.chromium.Chromium.XXXXXX");
-#endif
-}
-
bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) {
- base::ThreadRestrictions::AssertIOAllowed();
+ ThreadRestrictions::AssertIOAllowed();
// Windows compatibility: if to_path exists, from_path and to_path
// must be the same type, either both files, or both directories.
stat_wrapper_t to_file_info;
@@ -230,24 +215,39 @@ bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) {
if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0)
return true;
- if (!CopyDirectory(from_path, to_path, true))
+ if (!file_util::CopyDirectory(from_path, to_path, true))
return false;
Delete(from_path, true);
return true;
}
-bool ReplaceFileAndGetError(const FilePath& from_path,
- const FilePath& to_path,
- base::PlatformFileError* error) {
- base::ThreadRestrictions::AssertIOAllowed();
+bool ReplaceFile(const FilePath& from_path,
+ const FilePath& to_path,
+ PlatformFileError* error) {
+ ThreadRestrictions::AssertIOAllowed();
if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0)
return true;
if (error)
- *error = base::ErrnoToPlatformFileError(errno);
+ *error = ErrnoToPlatformFileError(errno);
return false;
}
+} // namespace base
+
+// -----------------------------------------------------------------------------
+
+namespace file_util {
+
+using base::stat_wrapper_t;
+using base::CallStat;
+using base::CallLstat;
+using base::FileEnumerator;
+using base::FilePath;
+using base::MakeAbsoluteFilePath;
+using base::RealPath;
+using base::VerifySpecificPathControlledByUser;
+
bool CopyDirectory(const FilePath& from_path,
const FilePath& to_path,
bool recursive) {
@@ -442,7 +442,7 @@ bool SetPosixFilePermissions(const FilePath& path,
// This function does NOT unlink() the file.
int CreateAndOpenFdForTemporaryFile(FilePath directory, FilePath* path) {
base::ThreadRestrictions::AssertIOAllowed(); // For call to mkstemp().
- *path = directory.Append(TempFileName());
+ *path = directory.Append(base::TempFileName());
const std::string& tmpdir_string = path->value();
// this should be OK since mkstemp just replaces characters in place
char* buffer = const_cast<char*>(tmpdir_string.c_str());
@@ -522,7 +522,8 @@ bool CreateNewTempDirectory(const FilePath::StringType& prefix,
if (!GetTempDir(&tmpdir))
return false;
- return CreateTemporaryDirInDirImpl(tmpdir, TempFileName(), new_temp_path);
+ return CreateTemporaryDirInDirImpl(tmpdir, base::TempFileName(),
+ new_temp_path);
}
bool CreateDirectoryAndGetError(const FilePath& full_path,