Page MenuHomePhabricator

Allow `Filesystem::walkToRoot` to walk to a given root directory
ClosedPublic

Authored by joshuaspence on Jun 8 2015, 10:18 AM.
Tags
None
Referenced Files
F13232630: D13202.diff
Tue, May 21, 1:25 AM
F13226862: D13202.id31905.diff
Sun, May 19, 11:44 PM
F13225912: D13202.id32092.diff
Sun, May 19, 6:15 PM
F13211338: D13202.diff
Fri, May 17, 5:41 AM
F13197896: D13202.id32091.diff
Mon, May 13, 2:06 AM
F13196588: D13202.diff
Sun, May 12, 11:23 PM
F13182030: D13202.id31991.diff
Thu, May 9, 6:30 PM
Unknown Object (File)
Fri, May 3, 5:28 AM
Subscribers

Details

Summary

Allow Filesystem::walkToRoot to walk to a given root directory. See D13185#139299.

Test Plan

Added unit tests.

Diff Detail

Repository
rPHU libphutil
Branch
master
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 6733
Build 6755: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

joshuaspence retitled this revision from to Allow `Filesystem::walkToRoot` to walk to a given root directory.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
epriestley edited edge metadata.
epriestley added inline comments.
src/filesystem/Filesystem.php
763

This will incorrectly remove directories named 0, 0.0, etc.

src/filesystem/__tests__/FilesystemTestCase.php
108

Three other useful cases might be:

  • Directory named 0.
  • Root and path identical.
  • Root not an ancestor of path.
This revision is now accepted and ready to land.Jun 8 2015, 8:45 PM

Yeah, I wanted to add something like this:

if (!self::isDescendant($path, $root)) {
  return array();
}

But this was problematic for my testing purposes because Filesystem::isDescendant($path, $root) requires $root and $path to actually exist. Would you be open to changing this method to be more general?

What do you think about creating some actual directories inside __tests__/data/ or similar and checking those?

Makes it slightly harder to get the expected values right for stuff above the library, but that seems surmountable to me.

Personally, I find the behavior of Filesystem::isDescendant to be non-obvious and so I think fixing that is the most correct solution. Adding directories in the __tests__/data directory is less obtrussive however.

@epriestley, I haven't had time to extend this further to check for "path is not a descendent of root". Is this fine to push as is?

joshuaspence edited edge metadata.

Add a bunch of test coverage

One possible issue, rest of it looks great to me.

src/filesystem/Filesystem.php
767

This is probably wrong on Windows -- there won't be a leading directory separator on $root, right?

Maybe cleaner would be:

while ($parts) {
  // compute the next thing
  // add it to the list
  // if we just added the root, break out of the loop
  // array_pop parts
}
joshuaspence marked 3 inline comments as done.
  • Improve Windows compatibility
  • Add some additional test cases
This revision was automatically updated to reflect the committed changes.