summaryrefslogtreecommitdiffstats
path: root/base/file_util.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-09 22:14:27 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-09 22:14:27 +0000
commitee5c29daf67e999166394e1acb0f89b755b70aaf (patch)
treedb73c6f93b688b554e08eefd805411cef1d8a940 /base/file_util.cc
parent2747db2640d2395115de7f3d168786b8ef6e3a81 (diff)
downloadchromium_src-ee5c29daf67e999166394e1acb0f89b755b70aaf.zip
chromium_src-ee5c29daf67e999166394e1acb0f89b755b70aaf.tar.gz
chromium_src-ee5c29daf67e999166394e1acb0f89b755b70aaf.tar.bz2
Move Contains() method to file_utils, stop relying on in extensions_protocol
Review URL: http://codereview.chromium.org/16805 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r--base/file_util.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index fe7b694..078e3afa 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -276,6 +276,33 @@ bool CloseFile(FILE* file) {
return fclose(file) == 0;
}
+bool ContainsPath(const FilePath &parent, const FilePath& child) {
+ FilePath abs_parent = FilePath(parent);
+ FilePath abs_child = FilePath(child);
+
+ if (!file_util::AbsolutePath(&abs_parent) ||
+ !file_util::AbsolutePath(&abs_child))
+ return false;
+
+#if defined(OS_WIN)
+ // file_util::AbsolutePath() does not flatten case on Windows, so we must do
+ // a case-insensitive compare.
+ if (!StartsWith(abs_child.value(), abs_parent.value(), false))
+#else
+ if (!StartsWithASCII(abs_child.value(), abs_parent.value(), true))
+#endif
+ return false;
+
+ // file_util::AbsolutePath() normalizes '/' to '\' on Windows, so we only need
+ // to check kSeparators[0].
+ if (abs_child.value().length() <= abs_parent.value().length() ||
+ abs_child.value()[abs_parent.value().length()] !=
+ FilePath::kSeparators[0])
+ return false;
+
+ return true;
+}
+
///////////////////////////////////////////////
// MemoryMappedFile