Skip to content

Commit f0bfd16

Browse files
committed
Merge pull request pocketarc#39 from sbtsrbayer/master
adds recursvie delete of newly emptied directories for sftp
2 parents 94f6ffe + 2358dc4 commit f0bfd16

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

git-deploy

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,27 @@ class SFTP extends Server {
403403
}
404404
}
405405

406+
protected function recursive_remove($file_or_directory, $if_dir = false) {
407+
$parent = dirname($file_or_directory);
408+
if ($this->connection->delete($file_or_directory, $if_dir)) {
409+
$filelist = $this->connection->nlist($parent);
410+
foreach ($filelist as $file) {
411+
if ($file != '.' and $file != '..') {
412+
return false;
413+
}
414+
}
415+
416+
$this->recursive_remove($parent, true);
417+
}
418+
}
419+
406420
public function mkdir($file) {
407421
$this->connection->mkdir($file);
408422
logmessage("Created directory: $file");
409423
}
410424

411425
public function unset_file($file) {
412-
$this->connection->delete($file, true);
426+
$this->recursive_remove($file, false);
413427
logmessage("Deleted: $file");
414428
}
415429

0 commit comments

Comments
 (0)