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
F14727526: D13202.id31983.diff
Sat, Jan 18, 4:35 AM
Unknown Object (File)
Wed, Jan 15, 10:51 AM
Unknown Object (File)
Wed, Jan 15, 3:28 AM
Unknown Object (File)
Tue, Jan 14, 10:26 PM
Unknown Object (File)
Sat, Dec 28, 2:59 PM
Unknown Object (File)
Fri, Dec 27, 1:00 PM
Unknown Object (File)
Sun, Dec 22, 1:18 AM
Unknown Object (File)
Thu, Dec 19, 8:14 PM
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 Skipped
Build Status
Buildable 6657
Build 6679: [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
755

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

src/filesystem/__tests__/FilesystemTestCase.php
253

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
759

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.