Skip to content

Commit 2ba0da5

Browse files
committed
generate pack index on config
1 parent 663f80b commit 2ba0da5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Service/ChunkService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class ChunkService {
6969

7070
public const BACKUP_SCRIPT = 'restore.php';
7171
public const APP_ZIP = 'app.zip';
72+
public const PREFIX = '.backup.';
73+
7274

7375
/** @var FilesService */
7476
private $filesService;
@@ -179,7 +181,7 @@ public function restoreChunk(
179181
$zip->extractTo($root, ($filename === '') ? null : $filename);
180182
$this->closeZipArchive($zip);
181183

182-
unlink($root . '.backup.' . $chunk->getName() . '.json');
184+
unlink($root . self::PREFIX . $chunk->getName() . '.json');
183185
// $this->restoreFromArchive($archive, $root);
184186
// $this->deleteArchive($backup, $archive, 'zip');
185187
}
@@ -261,7 +263,7 @@ public function listFilesFromChunk(RestoringPoint $point, RestoringChunk $chunk)
261263
* @param ZipArchive $zip
262264
*/
263265
public function listFilesFromZip(RestoringChunk $archive, ZipArchive $zip): void {
264-
$json = $zip->getFromName('.backup.' . $archive->getName() . '.json');
266+
$json = $zip->getFromName(self::PREFIX . $archive->getName() . '.json');
265267
if (!$json) {
266268
return;
267269
}
@@ -492,7 +494,7 @@ public function generateZip(RestoringPoint $point, RestoringChunk $chunk): ZipSt
492494
public function finalizeZip(ZipStreamer $zip, RestoringChunk $archive): void {
493495
$str = json_encode($archive->getResume(), JSON_PRETTY_PRINT);
494496
$read = fopen('data://text/plain,' . $str, 'rb');
495-
$zip->addFileFromStream($read, '.backup.' . $archive->getName() . '.json');
497+
$zip->addFileFromStream($read, self::PREFIX . $archive->getName() . '.json');
496498

497499
$zip->finalize();
498500
}
@@ -505,7 +507,12 @@ public function finalizeZip(ZipStreamer $zip, RestoringChunk $archive): void {
505507
private function finalizeChunk(RestoringPoint $point, RestoringChunk $chunk) {
506508
try {
507509
$folder = $this->getChunkFolder($point, $chunk);
508-
$folder->newFile('.backup.' . $chunk->getName() . '.json', json_encode($chunk->getResume(), JSON_PRETTY_PRINT));
510+
if ($this->configService->getAppValueBool(ConfigService::PACK_INDEX)) {
511+
$folder->newFile(
512+
self::PREFIX . $chunk->getName() . '.json',
513+
json_encode($chunk->getResume(), JSON_PRETTY_PRINT)
514+
);
515+
}
509516
} catch (Exception $e) {
510517
}
511518
}

lib/Service/ConfigService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ConfigService {
6464
public const PACK_ENCRYPT = 'pack_encrypt';
6565
public const PACK_COMPRESS = 'pack_compress';
6666
public const PACK_INDEX = 'pack_index';
67+
public const PACK_REMOTE_INDEX = 'pack_remote_index';
6768

6869
public const ENCRYPTION_KEY = 'encryption_key';
6970
public const TIME_SLOTS = 'time_slots';
@@ -95,7 +96,7 @@ class ConfigService {
9596
self::PACK_ENCRYPT => '1',
9697
self::PACK_COMPRESS => '1',
9798
self::PACK_INDEX => '1',
98-
99+
self::PACK_REMOTE_INDEX => '0',
99100
self::CHUNK_SIZE => 4000,
100101
self::CHUNK_PART_SIZE => 100
101102
];

0 commit comments

Comments
 (0)