sha256 sanity
Shorten files names Exclude express and differential files Only append hash suffix for duplicate files names (e.g. 22458 LPs for some langs)
This commit is contained in:
parent
645c81c109
commit
a2ec23d667
73
get.php
73
get.php
@ -164,8 +164,7 @@ function uupGetFiles(
|
||||
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
||||
}
|
||||
|
||||
if(!$sha256capable) {
|
||||
$baseless = preg_grep('/^baseless_|-baseless\....$/i', array_keys($filesInfoList));
|
||||
$baseless = preg_grep('/^baseless_|Windows10\.0-KB.*-EXPRESS|SSU-.*-EXPRESS/i', array_keys($filesInfoList));
|
||||
foreach($baseless as $val) {
|
||||
if(isset($filesInfoList[$val])) unset($filesInfoList[$val]);
|
||||
}
|
||||
@ -174,8 +173,8 @@ function uupGetFiles(
|
||||
$psf = preg_grep('/\.psf$/i', $psf);
|
||||
|
||||
$psfk = preg_grep('/Windows10\.0-KB.*/i', $psf);
|
||||
$psfk = preg_grep('/.*-EXPRESS|.*-baseless/i', $psfk, PREG_GREP_INVERT);
|
||||
if($build > 21380) foreach($psfk as $key => $val) {
|
||||
$psfk = preg_grep('/.*-EXPRESS/i', $psfk, PREG_GREP_INVERT);
|
||||
foreach($psfk as $key => $val) {
|
||||
if(isset($psf[$key])) unset($psf[$key]);
|
||||
}
|
||||
unset($psfk);
|
||||
@ -201,7 +200,6 @@ function uupGetFiles(
|
||||
}
|
||||
}
|
||||
unset($removeFiles);
|
||||
}
|
||||
|
||||
$filesInfoKeys = array_keys($filesInfoList);
|
||||
|
||||
@ -381,9 +379,23 @@ function uupGetOnlineFiles($updateId, $rev, $info, $cacheRequests, $type) {
|
||||
}
|
||||
|
||||
if($sha256capable) {
|
||||
$n = strrpos($name, '.');
|
||||
if($n === false) $n = strlen($name);
|
||||
$newName = substr($name, 0, $n).'_'.substr($sha1, 0, 8).substr($name, $n);
|
||||
$tempname = uupCleanSha256($name);
|
||||
if(isset($files[$tempname])) {
|
||||
if(preg_match('/\.cab$/i', $tempname)) {
|
||||
if($size > $files[$tempname]['size']) {
|
||||
$express = 'baseless_'.$tempname;
|
||||
$files[$express] = $files[$tempname];
|
||||
unset($files[$tempname]);
|
||||
$newName = $tempname;
|
||||
} else {
|
||||
$newName = 'baseless_'.$tempname;
|
||||
}
|
||||
} else {
|
||||
$newName = uupAppendSha1($tempname, $sha1);
|
||||
}
|
||||
} else {
|
||||
$newName = $tempname;
|
||||
}
|
||||
} else {
|
||||
$newName = $uupCleanFunc($name);
|
||||
}
|
||||
@ -450,9 +462,29 @@ function uupGetOfflineFiles($info) {
|
||||
$sha256 = isset($val['sha256']) ? $val['sha256'] : null;
|
||||
|
||||
if($sha256capable) {
|
||||
$n = strrpos($name, '.');
|
||||
if($n === false) $n = strlen($name);
|
||||
$newName = substr($name, 0, $n).'_'.substr($sha1, 0, 8).substr($name, $n);
|
||||
// clean file name
|
||||
$tempname = uupCleanSha256($name);
|
||||
if(isset($files[$tempname])) {
|
||||
// check existing file with the same name
|
||||
if(preg_match('/\.cab$/i', $tempname)) {
|
||||
// compare cab files only
|
||||
if($size > $files[$tempname]['size']) {
|
||||
// if the existing file is smaller, rename it
|
||||
$express = 'baseless_'.$tempname;
|
||||
$files[$express] = $files[$tempname];
|
||||
unset($files[$tempname]);
|
||||
$newName = $tempname;
|
||||
} else {
|
||||
// if the new file is smaller, rename it
|
||||
$newName = 'baseless_'.$tempname;
|
||||
}
|
||||
} else {
|
||||
// not a cab file, append hash to differentiate
|
||||
$newName = uupAppendSha1($tempname, $sha1);
|
||||
}
|
||||
} else {
|
||||
$newName = $tempname;
|
||||
}
|
||||
} else {
|
||||
$newName = $uupCleanFunc($name);
|
||||
}
|
||||
@ -478,6 +510,25 @@ function uupGetOfflineFiles($info) {
|
||||
return $files;
|
||||
}
|
||||
|
||||
function uupAppendSha1($name, $sha1) {
|
||||
$n = strrpos($name, '.');
|
||||
if($n === false) $n = strlen($name);
|
||||
return substr($name, 0, $n).'_'.substr($sha1, 0, 8).substr($name, $n);
|
||||
}
|
||||
|
||||
function uupCleanSha256($name) {
|
||||
$replace = array(
|
||||
'MetadataESD_' => null,
|
||||
'metadataesd_' => null,
|
||||
'~31bf3856ad364e35' => null,
|
||||
'~~.' => '.',
|
||||
'~.' => '.',
|
||||
'~' => '-',
|
||||
);
|
||||
|
||||
return strtr($name, $replace);
|
||||
}
|
||||
|
||||
function uupCleanName($name) {
|
||||
$replace = array(
|
||||
'cabs_' => null,
|
||||
|
Loading…
Reference in New Issue
Block a user