Fix handling for backups; correctly send along ignored files & directories

This commit is contained in:
Dane Everitt 2020-04-18 23:26:59 -07:00
parent b6a0cca0f9
commit 00b0d30c60
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
8 changed files with 31 additions and 16 deletions

View file

@ -87,7 +87,9 @@ class BackupController extends ClientApiController
}
$backup = $this->initiateBackupService
->setIgnoredFiles($request->input('ignored'))
->setIgnoredFiles(
explode(PHP_EOL, $request->input('ignored') ?? '')
)
->handle($server, $request->input('name'));
return $this->fractal->item($backup)

View file

@ -22,7 +22,7 @@ class StoreBackupRequest extends ClientApiRequest
{
return [
'name' => 'nullable|string|max:255',
'ignore' => 'nullable|string',
'ignored' => 'nullable|string',
];
}
}

View file

@ -13,8 +13,8 @@ class ReportBackupCompleteRequest extends FormRequest
{
return [
'successful' => 'boolean',
'checksum' => 'string|required_if:successful,true',
'size' => 'numeric|required_if:successful,true',
'checksum' => 'nullable|string|required_if:successful,true',
'size' => 'nullable|numeric|required_if:successful,true',
];
}
}

View file

@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property int $server_id
* @property int $uuid
* @property string $name
* @property string $ignored_files
* @property string[] $ignored_files
* @property string $disk
* @property string|null $sha256_hash
* @property int $bytes
@ -45,6 +45,7 @@ class Backup extends Model
protected $casts = [
'id' => 'int',
'bytes' => 'int',
'ignored_files' => 'array',
];
/**
@ -69,7 +70,7 @@ class Backup extends Model
'server_id' => 'bail|required|numeric|exists:servers,id',
'uuid' => 'required|uuid',
'name' => 'required|string',
'ignored_files' => 'string',
'ignored_files' => 'array',
'disk' => 'required|string',
'sha256_hash' => 'nullable|string',
'bytes' => 'numeric',

View file

@ -29,7 +29,7 @@ class DaemonBackupRepository extends DaemonRepository
[
'json' => [
'uuid' => $backup->uuid,
'ignored_files' => explode(PHP_EOL, $backup->ignored_files),
'ignored_files' => $backup->ignored_files,
],
]
);

View file

@ -4,6 +4,7 @@ namespace Pterodactyl\Services\Backups;
use Ramsey\Uuid\Uuid;
use Carbon\CarbonImmutable;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Backup;
use Pterodactyl\Models\Server;
use Illuminate\Database\ConnectionInterface;
@ -13,7 +14,7 @@ use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
class InitiateBackupService
{
/**
* @var string|null
* @var string[]|null
*/
private $ignoredFiles;
@ -52,12 +53,23 @@ class InitiateBackupService
/**
* Sets the files to be ignored by this backup.
*
* @param string|null $ignored
* @param string[]|null $ignored
* @return $this
*/
public function setIgnoredFiles(?string $ignored)
public function setIgnoredFiles(?array $ignored)
{
$this->ignoredFiles = $ignored;
if (is_array($ignored)) {
foreach ($ignored as $value) {
Assert::string($value);
}
}
// Set the ignored files to be any values that are not empty in the array. Don't use
// the PHP empty function here incase anything that is "empty" by default (0, false, etc.)
// were passed as a file or folder name.
$this->ignoredFiles = is_null($ignored) ? [] : array_filter($ignored, function ($value) {
return strlen($value) > 0;
});
return $this;
}
@ -79,7 +91,7 @@ class InitiateBackupService
'server_id' => $server->id,
'uuid' => Uuid::uuid4()->toString(),
'name' => trim($name) ?: sprintf('Backup at %s', CarbonImmutable::now()->toDateTimeString()),
'ignored_files' => $this->ignoredFiles ?? '',
'ignored_files' => is_array($this->ignoredFiles) ? array_values($this->ignoredFiles) : [],
'disk' => 'local',
], true, true);

View file

@ -1,10 +1,10 @@
import { rawDataToServerBackup, ServerBackup } from '@/api/server/backups/getServerBackups';
import http from '@/api/http';
export default (uuid: string, name?: string, ignore?: string): Promise<ServerBackup> => {
export default (uuid: string, name?: string, ignored?: string): Promise<ServerBackup> => {
return new Promise((resolve, reject) => {
http.post(`/api/client/servers/${uuid}/backups`, {
name, ignore,
name, ignored,
})
.then(({ data }) => resolve(rawDataToServerBackup(data)))
.catch(reject);

View file

@ -33,7 +33,7 @@ const ModalContent = ({ ...props }: RequiredModalProps) => {
</div>
<div className={'mb-6'}>
<FormikFieldWrapper
name={'ignore'}
name={'ignored'}
label={'Ignored Files & Directories'}
description={`
Enter the files or folders to ignore while generating this backup. Leave blank to use
@ -43,7 +43,7 @@ const ModalContent = ({ ...props }: RequiredModalProps) => {
`}
>
<FormikField
name={'contents'}
name={'ignored'}
component={'textarea'}
className={'input-dark h-32'}
/>