diff --git a/src/filesystem/Filesystem.php b/src/filesystem/Filesystem.php --- a/src/filesystem/Filesystem.php +++ b/src/filesystem/Filesystem.php @@ -777,22 +777,36 @@ * @return list List of parent paths, including the provided path. * @task directory */ - public static function walkToRoot($path, $root = '/') { + public static function walkToRoot($path, $root = null) { $path = self::resolvePath($path); - $root = self::resolvePath($root); if (is_link($path)) { $path = realpath($path); } - if (is_link($root)) { - $root = realpath($root); - } - // NOTE: We don't use `isDescendant()` here because we don't want to reject - // paths which don't exist on disk. - $root_list = new FileList(array($root)); - if (!$root_list->contains($path)) { - return array(); + // NOTE: On Windows, paths start like "C:\", so "/" does not contain + // every other path. We could possibly special case "/" to have the same + // meaning on Windows that it does on Linux, but just special case the + // common case for now. See PHI817. + if ($root !== null) { + $root = self::resolvePath($root); + + if (is_link($root)) { + $root = realpath($root); + } + + // NOTE: We don't use `isDescendant()` here because we don't want to + // reject paths which don't exist on disk. + $root_list = new FileList(array($root)); + if (!$root_list->contains($path)) { + return array(); + } + } else { + if (phutil_is_windows()) { + $root = null; + } else { + $root = '/'; + } } $walk = array();