Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit d8fb90a

Browse files
committed
✨ 支持多种文件检查策略
1 parent af4e115 commit d8fb90a

File tree

5 files changed

+87
-6
lines changed

5 files changed

+87
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ $config=[
6161
],
6262
"file"=> [
6363
"cache_dir"=> "./cache",//缓存文件夹
64-
"check"=> "hash",//检查文件策略(hash:检查文件hash size:检查文件大小 exists:检查文件是否存在)
64+
"check"=> "size",//检查文件策略(hash:检查文件hash size:检查文件大小 exists:检查文件是否存在)
6565
],
6666
"advanced"=> [
6767
"keepalive"=> 60,//keepalive时间,秒为单位(不建议调整)
6868
"MaxConcurrent"=> 30,//下载使用的线程
69-
"Debug"=> true,//Debug开关
69+
"Debug"=> false,//Debug开关
7070
],
7171
];
7272
```

config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"file"=> [
1212
"cache_dir"=> "./cache",//缓存文件夹
13-
"check"=> "hash",//检查文件策略(hash:检查文件hash size:检查文件大小 exists:检查文件是否存在)
13+
"check"=> "size",//检查文件策略(hash:检查文件hash size:检查文件大小 exists:检查文件是否存在)
1414
],
1515
"advanced"=> [
1616
"keepalive"=> 60,//keepalive时间,秒为单位(不建议调整)

inc/cluster.php

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ class FilesCheck {
243243

244244
public function __construct($filesList) {
245245
$this->filesList = $filesList;
246-
mlog("检查策略:hash");
247246
}
248247

249248
public function FilesCheckerhash() {
249+
mlog("检查策略:hash");
250250
$bar = new CliProgressBar(count($this->filesList));
251251
$bar->setDetails("[FileCheck]");
252252
$bar->display();
@@ -282,4 +282,67 @@ public function FilesCheckerhash() {
282282
return $this->Missfile;
283283
}
284284

285+
public function FilesCheckersize() {
286+
mlog("检查策略:size");
287+
$bar = new CliProgressBar(count($this->filesList));
288+
$bar->setDetails("[FileCheck]");
289+
$bar->display();
290+
foreach ($this->filesList as $file) {
291+
global $shouldExit;
292+
global $DOWNLOAD_DIR;
293+
if ($shouldExit) {
294+
return;
295+
break;
296+
}
297+
if (!file_exists($DOWNLOAD_DIR.'/'.substr($file->hash, 0, 2).'/'.$file->hash)){
298+
$this->Missfile[] = new BMCLAPIFile(
299+
$file->path,
300+
$file->hash,
301+
$file->size,
302+
$file->mtime
303+
);
304+
}
305+
else{
306+
if (filesize($DOWNLOAD_DIR.'/'.substr($file->hash, 0, 2).'/'.$file->hash) != $file->size) {
307+
$this->Missfile[] = new BMCLAPIFile(
308+
$file->path,
309+
$file->hash,
310+
$file->size,
311+
$file->mtime
312+
);
313+
}
314+
}
315+
$bar->progress();
316+
}
317+
$bar->display();
318+
$bar->end();
319+
return $this->Missfile;
320+
}
321+
322+
public function FilesCheckerexists() {
323+
mlog("检查策略:exists");
324+
$bar = new CliProgressBar(count($this->filesList));
325+
$bar->setDetails("[FileCheck]");
326+
$bar->display();
327+
foreach ($this->filesList as $file) {
328+
global $shouldExit;
329+
global $DOWNLOAD_DIR;
330+
if ($shouldExit) {
331+
return;
332+
break;
333+
}
334+
if (!file_exists($DOWNLOAD_DIR.'/'.substr($file->hash, 0, 2).'/'.$file->hash)){
335+
$this->Missfile[] = new BMCLAPIFile(
336+
$file->path,
337+
$file->hash,
338+
$file->size,
339+
$file->mtime
340+
);
341+
}
342+
$bar->progress();
343+
}
344+
$bar->display();
345+
$bar->end();
346+
return $this->Missfile;
347+
}
285348
}

inc/socketio.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function __construct($url,$token,$kattl) {
1313
$this->url = $url;
1414
$this->token = $token;
1515
$this->kattl = $kattl;
16+
$katimeid = 0;
1617
}
1718
public function connect() {
1819
$this->client = $client = new Client($this->url, 443, true);
@@ -56,6 +57,7 @@ public function connect() {
5657
}
5758
if ($code[0] == '430'){
5859
$jsondata = json_decode(substr($data, strlen($code[0])),true);
60+
print_r($jsondata);
5961
if (isset($jsondata[0][1]['cert'])){
6062
$this->certdata = $jsondata;
6163
}

main.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,30 @@ function registerSigintHandler() {
5959
$cluster = new cluster($tokendata['token'],VERSION);
6060
$files = $cluster->getFileList();
6161
$FilesCheck = new FilesCheck($files);
62-
$Missfile = $FilesCheck->FilesCheckerhash();
62+
if ($config['file']['check'] == "hash"){
63+
$Missfile = $FilesCheck->FilesCheckerhash();
64+
}
65+
elseif($config['file']['check'] == "size"){
66+
$Missfile = $FilesCheck->FilesCheckersize();
67+
}
68+
elseif($config['file']['check'] == "exists"){
69+
$Missfile = $FilesCheck->FilesCheckerexists();
70+
}
6371
if (is_array($Missfile)){
6472
mlog("缺失/损坏".count($Missfile)."个文件");
6573
while(is_array($Missfile)){
6674
$download = new download($Missfile,$config['advanced']['MaxConcurrent']);
6775
$download->downloadFiles();
6876
$FilesCheck = new FilesCheck($Missfile);
69-
$Missfile = $FilesCheck->FilesCheckerhash();
77+
if ($config['file']['check'] == "hash"){
78+
$Missfile = $FilesCheck->FilesCheckerhash();
79+
}
80+
elseif($config['file']['check'] == "size"){
81+
$Missfile = $FilesCheck->FilesCheckersize();
82+
}
83+
elseif($config['file']['check'] == "exists"){
84+
$Missfile = $FilesCheck->FilesCheckerexists();
85+
}
7086
if (is_array($Missfile)){
7187
//mlog("缺失/损坏".count($Missfile)."个文件");
7288
}

0 commit comments

Comments
 (0)