Chromium Code Reviews| Index: base/file_util.cc |
| diff --git a/base/file_util.cc b/base/file_util.cc |
| index fe7b6947167655a52feda98c25f6883d3867c883..078e3afa2e5ac6c2271fb9436c18ec16d2e2db75 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 |
|
Erik does not do reviews
2009/01/12 17:14:05
#else if defined(OS_POSIX)
|
| + if (!StartsWithASCII(abs_child.value(), abs_parent.value(), true)) |
|
Erik does not do reviews
2009/01/12 17:14:05
Put a comment / TODO / bug in here to reference th
|
| +#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 |