Skip to content

Commit

Permalink
fix(): error too many open files
Browse files Browse the repository at this point in the history
  • Loading branch information
al3xLvs committed Jun 20, 2019
1 parent 4330989 commit ea5ea83
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
Binary file modified rtorrent-cleaner-php5.phar
Binary file not shown.
Binary file modified rtorrent-cleaner-php7.phar
Binary file not shown.
19 changes: 2 additions & 17 deletions src/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function getFileListFromRtorrent()
$progressBar->advance(1);
}

$this->directories = array_unique($this->directories);
$this->directories = Helpers::getParentFolder($this->directories);
$progressBar->setMessage('<fg=green>completed successfully!</>', 'status');
$progressBar->finish();

Expand Down Expand Up @@ -101,11 +101,6 @@ protected function getFileListFromDisk()
$i++;
}

$this->localFileData = array_intersect_key(
$this->localFileData,
array_unique(array_map('serialize', $this->localFileData))
);

return $this;
}

Expand All @@ -129,16 +124,6 @@ public function getFilesMissingFromRtorrent()
return Helpers::find_diff($this->rtorrentFileData, $this->localFileData);
}

public function getDirectories()
{
return $this->directories;
}

public function setDirectories($directories)
{
$this->directories = $directories;
}

public function getEmptyDirectory()
{
$emptyDirectory = [];
Expand All @@ -163,7 +148,7 @@ public function getEmptyDirectory()
}
}

return array_unique($emptyDirectory);
return $emptyDirectory;
}

public function removeDirectory($emptyDirectory)
Expand Down
7 changes: 0 additions & 7 deletions src/Command/RemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$console->writeln("directory: <fg=yellow>{$folder}</> has been removed");
}

foreach ($cleaner->getDirectories() as $dir) {
if (is_dir($dir)) {
$directories[] = $dir;
}
}

$cleaner->setDirectories($directories);
$emptyDirectory = $cleaner->getEmptyDirectory();
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,19 @@ public static function title($title, $output)

return $output->writeln([$top, ''.$title.'', $bottom, '']);
}

public function getParentFolder($array)
{
sort($array);
$directories = [];

foreach ($array as $value) {
$test_path = preg_replace('#\/([^\/]+)$#', '', $value);
if (!in_array($test_path, $directories)) {
$directories[] = $value;
}
}

return array_unique($directories);
}
}

0 comments on commit ea5ea83

Please sign in to comment.