Skip to content

Instantly share code, notes, and snippets.

@WyriHaximus
Created September 17, 2014 19:29
Show Gist options
  • Save WyriHaximus/b4d9b5d417c160bb4e24 to your computer and use it in GitHub Desktop.
Save WyriHaximus/b4d9b5d417c160bb4e24 to your computer and use it in GitHub Desktop.
public function chownRecursive($uid = -1, $gid = -1) {
$deferred = new Deferred();
$this->ls()->then(function($list) use ($deferred, $uid, $gid) {
$this->filesystem->getLoop()->futureTick(function() use ($list, $deferred, $uid, $gid) {
$promises = [];
foreach ($list as $node) {
if ($node instanceof Directory) {
$promises[] = $node->chownRecursive($uid, $gid);
} else {
$promises[] = $node->chown($uid, $gid);
}
}
\React\Promise\all($promises)->then(function() use ($deferred, $uid, $gid) {
$this->chown($uid, $gid)->then(function() use ($deferred) {
$deferred->resolve();
});
});
});
});
return $deferred->promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment