summaryrefslogtreecommitdiffstats
path: root/base/file_util.cc
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-30 23:54:04 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-30 23:54:04 +0000
commit640517fdd23e08ed95cf129d27457db817ee6124 (patch)
tree2674bc857b9d1b566e05bcfa1dd5c8cfd1897dbf /base/file_util.cc
parentf92ed219c9aeeed79993d1d32f34e5d5c9888dbe (diff)
downloadchromium_src-640517fdd23e08ed95cf129d27457db817ee6124.zip
chromium_src-640517fdd23e08ed95cf129d27457db817ee6124.tar.gz
chromium_src-640517fdd23e08ed95cf129d27457db817ee6124.tar.bz2
Begin the first small step towards using FilePath everywhere:
- Add some transition APIs. - Start migrating some code to transition APIs. Review URL: http://codereview.chromium.org/8825 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4254 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r--base/file_util.cc68
1 files changed, 59 insertions, 9 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 49f063e..e196ff8 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -8,6 +8,7 @@
#include <fstream>
+#include "base/file_path.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "unicode/uniset.h"
@@ -229,20 +230,14 @@ void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
file_name->swap(result);
}
-bool ContentsEqual(const std::wstring& filename1,
- const std::wstring& filename2) {
+bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) {
// We open the file in binary format even if they are text files because
// we are just comparing that bytes are exactly same in both files and not
// doing anything smart with text formatting.
-#if defined(OS_WIN)
- std::ifstream file1(filename1.c_str(), std::ios::in | std::ios::binary);
- std::ifstream file2(filename2.c_str(), std::ios::in | std::ios::binary);
-#elif defined(OS_POSIX)
- std::ifstream file1(WideToUTF8(filename1).c_str(),
+ std::ifstream file1(filename1.value().c_str(),
std::ios::in | std::ios::binary);
- std::ifstream file2(WideToUTF8(filename2).c_str(),
+ std::ifstream file2(filename2.value().c_str(),
std::ios::in | std::ios::binary);
-#endif
// Even if both files aren't openable (and thus, in some sense, "equal"),
// any unusable file yields a result of "false".
@@ -300,5 +295,60 @@ bool CloseFile(FILE* file) {
return fclose(file) == 0;
}
+// Deprecated functions ----------------------------------------------------
+
+bool AbsolutePath(std::wstring* path_str) {
+ FilePath path;
+ if (!AbsolutePath(&path))
+ return false;
+ *path_str = path.ToWStringHack();
+ return true;
+}
+bool Delete(const std::wstring& path, bool recursive) {
+ return Delete(FilePath::FromWStringHack(path), recursive);
+}
+bool Move(const std::wstring& from_path, const std::wstring& to_path) {
+ return Move(FilePath::FromWStringHack(from_path),
+ FilePath::FromWStringHack(to_path));
+}
+bool CopyFile(const std::wstring& from_path, const std::wstring& to_path) {
+ return CopyFile(FilePath::FromWStringHack(from_path),
+ FilePath::FromWStringHack(to_path));
+}
+bool CopyDirectory(const std::wstring& from_path, const std::wstring& to_path,
+ bool recursive) {
+ return CopyDirectory(FilePath::FromWStringHack(from_path),
+ FilePath::FromWStringHack(to_path),
+ recursive);
+}
+bool PathExists(const std::wstring& path) {
+ return PathExists(FilePath::FromWStringHack(path));
+}
+bool DirectoryExists(const std::wstring& path) {
+ return DirectoryExists(FilePath::FromWStringHack(path));
+}
+bool ContentsEqual(const std::wstring& filename1,
+ const std::wstring& filename2) {
+ return ContentsEqual(FilePath::FromWStringHack(filename1),
+ FilePath::FromWStringHack(filename2));
+}
+bool CreateDirectory(const std::wstring& full_path) {
+ return CreateDirectory(FilePath::FromWStringHack(full_path));
+}
+bool GetCurrentDirectory(std::wstring* path_str) {
+ FilePath path;
+ if (!GetCurrentDirectory(&path))
+ return false;
+ *path_str = path.ToWStringHack();
+ return true;
+}
+bool GetTempDir(std::wstring* path_str) {
+ FilePath path;
+ if (!GetTempDir(&path))
+ return false;
+ *path_str = path.ToWStringHack();
+ return true;
+}
+
} // namespace