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
F14116973: D13202.diff
Thu, Nov 28, 5:05 PM
Unknown Object (File)
Tue, Nov 26, 7:54 AM
Unknown Object (File)
Tue, Nov 26, 7:54 AM
Unknown Object (File)
Tue, Nov 26, 7:53 AM
Unknown Object (File)
Tue, Nov 26, 7:53 AM
Unknown Object (File)
Tue, Nov 26, 7:53 AM
Unknown Object (File)
Tue, Nov 26, 7:53 AM
Unknown Object (File)
Tue, Nov 26, 7:31 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 6665
Build 6687: [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.