Skip to content

Commit 00b0d30

Browse files
committed
Fix handling for backups; correctly send along ignored files & directories
1 parent b6a0cca commit 00b0d30

File tree

8 files changed

+31
-16
lines changed

8 files changed

+31
-16
lines changed

app/Http/Controllers/Api/Client/Servers/BackupController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public function store(StoreBackupRequest $request, Server $server)
8787
}
8888

8989
$backup = $this->initiateBackupService
90-
->setIgnoredFiles($request->input('ignored'))
90+
->setIgnoredFiles(
91+
explode(PHP_EOL, $request->input('ignored') ?? '')
92+
)
9193
->handle($server, $request->input('name'));
9294

9395
return $this->fractal->item($backup)

app/Http/Requests/Api/Client/Servers/Backups/StoreBackupRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function rules(): array
2222
{
2323
return [
2424
'name' => 'nullable|string|max:255',
25-
'ignore' => 'nullable|string',
25+
'ignored' => 'nullable|string',
2626
];
2727
}
2828
}

app/Http/Requests/Api/Remote/ReportBackupCompleteRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public function rules()
1313
{
1414
return [
1515
'successful' => 'boolean',
16-
'checksum' => 'string|required_if:successful,true',
17-
'size' => 'numeric|required_if:successful,true',
16+
'checksum' => 'nullable|string|required_if:successful,true',
17+
'size' => 'nullable|numeric|required_if:successful,true',
1818
];
1919
}
2020
}

app/Models/Backup.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @property int $server_id
1010
* @property int $uuid
1111
* @property string $name
12-
* @property string $ignored_files
12+
* @property string[] $ignored_files
1313
* @property string $disk
1414
* @property string|null $sha256_hash
1515
* @property int $bytes
@@ -45,6 +45,7 @@ class Backup extends Model
4545
protected $casts = [
4646
'id' => 'int',
4747
'bytes' => 'int',
48+
'ignored_files' => 'array',
4849
];
4950

5051
/**
@@ -69,7 +70,7 @@ class Backup extends Model
6970
'server_id' => 'bail|required|numeric|exists:servers,id',
7071
'uuid' => 'required|uuid',
7172
'name' => 'required|string',
72-
'ignored_files' => 'string',
73+
'ignored_files' => 'array',
7374
'disk' => 'required|string',
7475
'sha256_hash' => 'nullable|string',
7576
'bytes' => 'numeric',

app/Repositories/Wings/DaemonBackupRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function backup(Backup $backup): ResponseInterface
2929
[
3030
'json' => [
3131
'uuid' => $backup->uuid,
32-
'ignored_files' => explode(PHP_EOL, $backup->ignored_files),
32+
'ignored_files' => $backup->ignored_files,
3333
],
3434
]
3535
);

app/Services/Backups/InitiateBackupService.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Ramsey\Uuid\Uuid;
66
use Carbon\CarbonImmutable;
7+
use Webmozart\Assert\Assert;
78
use Pterodactyl\Models\Backup;
89
use Pterodactyl\Models\Server;
910
use Illuminate\Database\ConnectionInterface;
@@ -13,7 +14,7 @@
1314
class InitiateBackupService
1415
{
1516
/**
16-
* @var string|null
17+
* @var string[]|null
1718
*/
1819
private $ignoredFiles;
1920

@@ -52,12 +53,23 @@ public function __construct(
5253
/**
5354
* Sets the files to be ignored by this backup.
5455
*
55-
* @param string|null $ignored
56+
* @param string[]|null $ignored
5657
* @return $this
5758
*/
58-
public function setIgnoredFiles(?string $ignored)
59+
public function setIgnoredFiles(?array $ignored)
5960
{
60-
$this->ignoredFiles = $ignored;
61+
if (is_array($ignored)) {
62+
foreach ($ignored as $value) {
63+
Assert::string($value);
64+
}
65+
}
66+
67+
// Set the ignored files to be any values that are not empty in the array. Don't use
68+
// the PHP empty function here incase anything that is "empty" by default (0, false, etc.)
69+
// were passed as a file or folder name.
70+
$this->ignoredFiles = is_null($ignored) ? [] : array_filter($ignored, function ($value) {
71+
return strlen($value) > 0;
72+
});
6173

6274
return $this;
6375
}
@@ -79,7 +91,7 @@ public function handle(Server $server, string $name = null): Backup
7991
'server_id' => $server->id,
8092
'uuid' => Uuid::uuid4()->toString(),
8193
'name' => trim($name) ?: sprintf('Backup at %s', CarbonImmutable::now()->toDateTimeString()),
82-
'ignored_files' => $this->ignoredFiles ?? '',
94+
'ignored_files' => is_array($this->ignoredFiles) ? array_values($this->ignoredFiles) : [],
8395
'disk' => 'local',
8496
], true, true);
8597

resources/scripts/api/server/backups/createServerBackup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { rawDataToServerBackup, ServerBackup } from '@/api/server/backups/getServerBackups';
22
import http from '@/api/http';
33

4-
export default (uuid: string, name?: string, ignore?: string): Promise<ServerBackup> => {
4+
export default (uuid: string, name?: string, ignored?: string): Promise<ServerBackup> => {
55
return new Promise((resolve, reject) => {
66
http.post(`/api/client/servers/${uuid}/backups`, {
7-
name, ignore,
7+
name, ignored,
88
})
99
.then(({ data }) => resolve(rawDataToServerBackup(data)))
1010
.catch(reject);

resources/scripts/components/server/backups/CreateBackupButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ModalContent = ({ ...props }: RequiredModalProps) => {
3333
</div>
3434
<div className={'mb-6'}>
3535
<FormikFieldWrapper
36-
name={'ignore'}
36+
name={'ignored'}
3737
label={'Ignored Files & Directories'}
3838
description={`
3939
Enter the files or folders to ignore while generating this backup. Leave blank to use
@@ -43,7 +43,7 @@ const ModalContent = ({ ...props }: RequiredModalProps) => {
4343
`}
4444
>
4545
<FormikField
46-
name={'contents'}
46+
name={'ignored'}
4747
component={'textarea'}
4848
className={'input-dark h-32'}
4949
/>

0 commit comments

Comments
 (0)