Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Handle cases where posts in pool were reordered - make sure to delete…
Browse files Browse the repository at this point in the history
… out of order files
  • Loading branch information
jacklul committed Jul 6, 2020
1 parent 8c84fb6 commit cc71783
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class App
*
* @var int
*/
private $VERSION = '1.4.1';
private $VERSION = '1.5.0';

/**
* App update URL
Expand Down Expand Up @@ -536,6 +536,7 @@ public function run()
print("\r" . $this->LINE_BUFFER . ' done ' . "\n\n");
}

$filesList = [];
$fileCount = 0;
$filesDownloaded = 0;
foreach ($posts as &$post) {
Expand All @@ -556,7 +557,7 @@ public function run()

$fileName = str_pad($fileCount, 3, "0", STR_PAD_LEFT) . '_' . $post['file']['md5'] . '.' . $post['file']['ext'];

if (!file_exists($downloadDir . '/' . $fileName) || md5_file($downloadDir . '/' . $fileName) != $post['file']['md5']) {
if (!file_exists($downloadDir . '/' . $fileName) || md5_file($downloadDir . '/' . $fileName) !== $post['file']['md5']) {
$this->LINE_BUFFER .= ' downloading post #' . $post['id'] . '...';

$contents = $this->cURL($post['file']['url']);
Expand All @@ -573,6 +574,8 @@ public function run()
} else {
print("\r" . $this->LINE_BUFFER . " no download required\n");
}

$filesList[] = $fileName;
}
unset($post);

Expand All @@ -585,7 +588,7 @@ public function run()
$md5 = md5_file($downloadDir . '/' . $fileInfo->getFilename());

foreach ($posts as $post) {
if ($md5 === $post['file']['md5']) {
if ($md5 === $post['file']['md5'] && in_array($fileInfo->getFilename(), $filesList, true)) {
continue 2;
}
}
Expand Down

0 comments on commit cc71783

Please sign in to comment.