summaryrefslogtreecommitdiffstats
path: root/base/file_util.h
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 17:32:10 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 17:32:10 +0000
commit37088fefa67704ad6f18e1e72e2e6292ba48ee1b (patch)
treeef54e2c068b1a63dfe29b01fb59af6e1148d16d3 /base/file_util.h
parente87ce0ff4a37f8e5bd0e4d7938bcf93b66d29ec9 (diff)
downloadchromium_src-37088fefa67704ad6f18e1e72e2e6292ba48ee1b.zip
chromium_src-37088fefa67704ad6f18e1e72e2e6292ba48ee1b.tar.gz
chromium_src-37088fefa67704ad6f18e1e72e2e6292ba48ee1b.tar.bz2
Part two of file_util porting. Almost all of the functionality has been ported, including the unit tests now. Some of this API isn't great, and should be cleaned up, but I'd like to hold off and do that in a followup changelist. More general code cleanup is likely needed here as well.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.h')
-rw-r--r--base/file_util.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/base/file_util.h b/base/file_util.h
index 4aac207..e3895e3 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -37,10 +37,13 @@
#if defined(OS_WIN)
#include <windows.h>
+#elif defined(OS_POSIX)
+#include <fts.h>
#endif
#include <stack>
#include <string>
+#include <vector>
#include "base/basictypes.h"
@@ -55,9 +58,15 @@ extern const wchar_t kPathSeparator;
//-----------------------------------------------------------------------------
// Functions that operate purely on a path string w/o touching the filesystem:
+// Returns a vector of all of the components of the provided path.
+void PathComponents(const std::wstring& path,
+ std::vector<std::wstring>* components);
+
// Returns true if the given path ends with a path separator character.
+// TODO(erikkay): remove this pointer version
bool EndsWithSeparator(std::wstring* path);
-
+bool EndsWithSeparator(const std::wstring& path);
+
// Modifies a string by trimming all trailing separators from the end.
void TrimTrailingSeparator(std::wstring* dir);
@@ -188,6 +197,7 @@ bool ContentsEqual(const std::wstring& filename1,
// Useful for unit tests.
bool ReadFileToString(const std::wstring& path, std::string* contents);
+#if defined(OS_WINDOWS)
// Resolve Windows shortcut (.LNK file)
// Argument path specifies a valid LNK file. On success, return true and put
// the URL into path. If path is a invalid .LNK file, return false.
@@ -218,13 +228,16 @@ bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination,
const wchar_t *working_dir, const wchar_t *arguments,
const wchar_t *description, const wchar_t *icon,
int icon_index);
+#endif
+
// Get the temporary directory provided by the system.
bool GetTempDir(std::wstring* path);
-// Creates a temporary file name, but does it not create the file. It accesses
-// the disk to do this, however. The full path is placed in 'temp_file', and the
-// function returns true if was successful in creating the file name.
+// Creates a temporary file. The full path is placed in 'temp_file', and the
+// function returns true if was successful in creating the file. The file will
+// be empty and all handles closed after this function returns.
+// TODO(erikkay): rename this function and track down all of the callers.
bool CreateTemporaryFileName(std::wstring* temp_file);
// Create a new directory under TempPath. If prefix is provided, the new
@@ -275,9 +288,18 @@ class FileEnumerator {
// files in one directory will be returned before any files in a
// subdirectory.
//
- // The last parameter is an optional pattern for which files to match. This
- // works like a Windows file pattern. For example, "*.txt" or "Foo???.doc".
+ // |file_type| specifies whether the enumerator should match files,
+ // directories, or both.
+ //
+ // |pattern| is an optional pattern for which files to match. This
+ // works like shell globbing. For example, "*.txt" or "Foo???.doc".
+ // However, be careful in specifying patterns that aren't cross platform
+ // since the underlying code uses OS-specific matching routines. In general,
+ // Windows matching is less featureful than others, so test there first.
// If unspecified, this will match all files.
+ // NOTE: the pattern only matches the contents of root_path, not files in
+ // recursive subdirectories.
+ // TODO(erikkay): Fix the pattern matching to work at all levels.
FileEnumerator(const std::wstring& root_path,
bool recursive,
FileEnumerator::FILE_TYPE file_type);
@@ -307,7 +329,9 @@ class FileEnumerator {
#if defined(OS_WIN)
WIN32_FIND_DATA find_data_;
HANDLE find_handle_;
-#endif // defined(OS_WIN)
+#elif defined(OS_POSIX)
+ FTS* fts_;
+#endif
DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator);
};