Skip to content

Commit

Permalink
feat: add verifying status progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Oct 25, 2020
1 parent 87ce9d8 commit 702ba1d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace marcocesarato\amwscan;

use ArrayIterator;
use CallbackFilterIterator;
use Exception;
use LimitIterator;
Expand Down Expand Up @@ -273,8 +274,7 @@ public function run($args = null)
Console::writeLine('Scanning ' . self::$pathScan, 2);

// Mapping files
Console::writeLine('Mapping, retrieving checksums and verifying files');
Console::displayLine('It may take a while, please wait...');
Console::writeLine('Mapping and retrieving checksums, please wait...', 2);
$iterator = $this->mapping();

// Counting files
Expand Down Expand Up @@ -674,7 +674,7 @@ private function modes()
/**
* Map files.
*
* @return CallbackFilterIterator
* @return ArrayIterator
*/
public function mapping()
{
Expand Down Expand Up @@ -714,11 +714,26 @@ public function mapping()
in_array($cur->getExtension(), self::getExtensions(), true);
});

$iterator = new CallbackFilterIterator($filtered, function ($cur) {
return $cur->isFile() && !Modules::isVerified($cur->getPathname());
});
$mapping = array();

$mapped = 0;
$count = iterator_count($filtered);

Console::writeBreak(1);
Console::writeLine('Verifying files checksum...', 2);

foreach ($filtered as $cur) {
Console::progress($mapped++, $count);
if ($cur->isFile() && !Modules::isVerified($cur->getPathname())) {
$mapping[] = $cur;
}
Console::progress($mapped, $count);
}
$iterator = new \ArrayObject($mapping);

Console::writeBreak(1);

return $iterator;
return $iterator->getIterator();
}

/**
Expand Down

0 comments on commit 702ba1d

Please sign in to comment.