mirror of
https://github.com/mbirth/tcl_update_db.git
synced 2024-12-26 04:24:07 +00:00
Better progress output.
This commit is contained in:
parent
e6297445f0
commit
6557e04fe4
@ -3,22 +3,34 @@
|
||||
|
||||
$bkup_dir = __DIR__ . '/../data/';
|
||||
|
||||
$ansi_csi = chr(27) . '[';
|
||||
$ansi_updel = $ansi_csi . 'F' . $ansi_csi . 'K';
|
||||
|
||||
echo 'Reading file list ...';
|
||||
$file_list = glob($bkup_dir . '*.xml');
|
||||
echo ' OK' . PHP_EOL;
|
||||
|
||||
echo 'Searching for duplicates ...' . PHP_EOL . PHP_EOL;
|
||||
|
||||
$hashes = array();
|
||||
foreach ($file_list as $file) {
|
||||
foreach ($file_list as $i => $file) {
|
||||
echo $ansi_updel . ($i+1) . '/' . count($file_list) . PHP_EOL;
|
||||
$filename = basename($file);
|
||||
$file_hash = sha1_file($file);
|
||||
|
||||
if (isset($hashes[$file_hash])) {
|
||||
$old_file = $hashes[$file_hash];
|
||||
if (md5_file($file) == md5_file($bkup_dir . $old_file)) {
|
||||
echo 'Duplicate file: ' . $filename . ' (first: ' . $old_file . ')' . PHP_EOL;
|
||||
echo $ansi_updel . 'Duplicate file: ' . $filename . ' (first: ' . $old_file . ')' . PHP_EOL . PHP_EOL;
|
||||
unlink($file);
|
||||
continue;
|
||||
}
|
||||
echo 'Possible SHA1 collision?' . PHP_EOL;
|
||||
echo $ansi_updel . 'Possible SHA1 collision?' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
$hashes[$file_hash] = $filename;
|
||||
flush();
|
||||
}
|
||||
|
||||
echo count($file_list) . ' files done.' . PHP_EOL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user