Skip to content

Commit 7dca704

Browse files
committed
adding process progression during create,pack,unpack
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent f37b7fa commit 7dca704

File tree

7 files changed

+200
-32
lines changed

7 files changed

+200
-32
lines changed

lib/Command/PointCreate.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use OCA\Backup\Exceptions\BackupScriptNotFoundException;
3939
use OCA\Backup\Exceptions\RestoringPointException;
4040
use OCA\Backup\Exceptions\SqlDumpException;
41+
use OCA\Backup\Service\OutputService;
4142
use OCA\Backup\Service\PointService;
4243
use OCP\Files\NotFoundException;
4344
use OCP\Files\NotPermittedException;
@@ -57,16 +58,21 @@ class PointCreate extends Base {
5758
/** @var PointService */
5859
private $pointService;
5960

61+
/** @var OutputService */
62+
private $outputService;
63+
6064

6165
/**
6266
* PointCreate constructor.
6367
*
6468
* @param PointService $pointService
69+
* @param OutputService $outputService
6570
*/
66-
public function __construct(PointService $pointService) {
71+
public function __construct(PointService $pointService, OutputService $outputService) {
6772
parent::__construct();
6873

6974
$this->pointService = $pointService;
75+
$this->outputService = $outputService;
7076
}
7177

7278

@@ -98,19 +104,24 @@ protected function configure() {
98104
* @throws Throwable
99105
*/
100106
protected function execute(InputInterface $input, OutputInterface $output): int {
107+
$o = $input->getOption('output');
108+
if ($o !== 'none' && $o !== 'json') {
109+
$this->outputService->setOutput($output);
110+
}
111+
101112
$point = $this->pointService->create(!$input->getOption('incremental'));
102113

103-
if ($input->getOption('output') === 'none') {
114+
if ($o === 'none') {
104115
return 0;
105116
}
106117

107-
108-
if ($input->getOption('output') === 'json') {
118+
if ($o === 'json') {
109119
$output->writeln(json_encode($point, JSON_PRETTY_PRINT));
110120

111121
return 0;
112122
}
113123

124+
$output->writeln('');
114125
$output->writeln('Restoring Point ID: <info>' . $point->getId() . '</info>');
115126

116127
return 0;

lib/Command/PointPack.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
namespace OCA\Backup\Command;
3333

3434
use OC\Core\Command\Base;
35-
use OCA\Backup\Exceptions\RestoringPointPackException;
35+
use OCA\Backup\Exceptions\RestoringPointLockException;
3636
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
37+
use OCA\Backup\Exceptions\RestoringPointPackException;
38+
use OCA\Backup\Service\OutputService;
3739
use OCA\Backup\Service\PackService;
3840
use OCA\Backup\Service\PointService;
3941
use OCP\Files\NotFoundException;
@@ -56,18 +58,27 @@ class PointPack extends Base {
5658
/** @var PackService */
5759
private $packService;
5860

61+
/** @var OutputService */
62+
private $outputService;
63+
5964

6065
/**
6166
* PointPack constructor.
6267
*
6368
* @param PointService $pointService
6469
* @param PackService $packService
70+
* @param OutputService $outputService
6571
*/
66-
public function __construct(PointService $pointService, PackService $packService) {
72+
public function __construct(
73+
PointService $pointService,
74+
PackService $packService,
75+
OutputService $outputService
76+
) {
6777
parent::__construct();
6878

6979
$this->pointService = $pointService;
7080
$this->packService = $packService;
81+
$this->outputService = $outputService;
7182
}
7283

7384

@@ -92,10 +103,12 @@ protected function configure() {
92103
* @throws NotPermittedException
93104
* @throws RestoringPointPackException
94105
* @throws RestoringPointNotFoundException
106+
* @throws RestoringPointLockException
95107
*/
96108
protected function execute(InputInterface $input, OutputInterface $output): int {
97109
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));
98110
$this->pointService->initBaseFolder($point);
111+
$this->outputService->setOutput($output);
99112
$this->packService->packPoint($point, true);
100113

101114
return 0;

lib/Command/PointUnpack.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
3535
use OC\Core\Command\Base;
3636
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
37+
use OCA\Backup\Service\OutputService;
3738
use OCA\Backup\Service\PackService;
3839
use OCA\Backup\Service\PointService;
3940
use OCA\Backup\Service\RemoteStreamService;
@@ -61,24 +62,30 @@ class PointUnpack extends Base {
6162
/** @var RemoteStreamService */
6263
private $remoteStreamService;
6364

65+
/** @var OutputService */
66+
private $outputService;
67+
6468

6569
/**
6670
* PointUnpack constructor.
6771
*
6872
* @param PointService $pointService
6973
* @param PackService $packService
7074
* @param RemoteStreamService $remoteStreamService
75+
* @param OutputService $outputService
7176
*/
7277
public function __construct(
7378
PointService $pointService,
7479
PackService $packService,
75-
RemoteStreamService $remoteStreamService
80+
RemoteStreamService $remoteStreamService,
81+
OutputService $outputService
7682
) {
7783
parent::__construct();
7884

7985
$this->pointService = $pointService;
8086
$this->packService = $packService;
8187
$this->remoteStreamService = $remoteStreamService;
88+
$this->outputService = $outputService;
8289
}
8390

8491

@@ -106,6 +113,7 @@ protected function configure() {
106113
* @throws Throwable
107114
*/
108115
protected function execute(InputInterface $input, OutputInterface $output): int {
116+
$this->outputService->setOutput($output);
109117
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));
110118

111119
$this->pointService->initBaseFolder($point);

lib/Service/ChunkService.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class ChunkService {
8080
/** @var EncryptService */
8181
private $encryptService;
8282

83+
/** @var OutputService */
84+
private $outputService;
85+
8386
/** @var ConfigService */
8487
private $configService;
8588

@@ -89,15 +92,18 @@ class ChunkService {
8992
*
9093
* @param FilesService $filesService
9194
* @param EncryptService $encryptService
95+
* @param OutputService $outputService
9296
* @param ConfigService $configService
9397
*/
9498
public function __construct(
9599
FilesService $filesService,
96100
EncryptService $encryptService,
101+
OutputService $outputService,
97102
ConfigService $configService
98103
) {
99104
$this->filesService = $filesService;
100105
$this->encryptService = $encryptService;
106+
$this->outputService = $outputService;
101107
$this->configService = $configService;
102108
}
103109

@@ -115,10 +121,12 @@ public function createChunks(RestoringPoint $point): void {
115121
continue;
116122
}
117123

124+
$this->o(' * <info>' . $data->getName() . '</info>: ', false);
118125
$this->filesService->initRestoringData($data);
119126
if (!$data->isLocked()) {
120127
$this->filesService->fillRestoringData($data, $data->getUniqueFile());
121128
}
129+
$this->o($data->getRoot() . $data->getPath() . ', ' . count($data->getFiles()) . ' files');
122130
$data->setLocked(true);
123131

124132
$this->fillChunks($point, $data);
@@ -353,6 +361,7 @@ private function fillChunks(RestoringPoint $point, RestoringData $data) {
353361
$files = $data->getFiles();
354362
while (!empty($files)) {
355363
$archive = $this->generateChunk($point, $data, $files);
364+
$this->o(' - ' . $archive->getName());
356365
$this->updateChecksum($point, $archive);
357366

358367
$data->addChunk($archive);
@@ -978,4 +987,14 @@ public function getChunkFolder(
978987

979988
return $folder;
980989
}
990+
991+
992+
/**
993+
* @param string $line
994+
* @param bool $ln
995+
*/
996+
private function o(string $line, bool $ln = true): void {
997+
$this->outputService->o($line, $ln);
998+
}
999+
9811000
}

lib/Service/EncryptService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function decryptString(string $encrypted, string $key): string {
148148
*
149149
* @return string
150150
* @throws EncryptionKeyException
151+
* @throws PackEncryptException
151152
* @throws SodiumException
152153
*/
153154
public function encryptFile(string $input, string $output, string $name): string {

0 commit comments

Comments
 (0)