Skip to content

Commit

Permalink
fix: relative_path too short, example: /app
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 authored and freekmurze committed Aug 10, 2023
1 parent b42f194 commit 3a86fbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Tasks/Backup/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ protected static function determineNameOfFileInZip(string $pathToFile, string $p
$zipDirectory = pathinfo($pathToZip, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR;

if (Str::startsWith($fileDirectory, $zipDirectory)) {
return str_replace($zipDirectory, '', $pathToFile);
return substr($pathToFile, strlen($zipDirectory));
}

if ($relativePath && $relativePath != DIRECTORY_SEPARATOR && Str::startsWith($fileDirectory, $relativePath)) {
return str_replace($relativePath, '', $pathToFile);
return substr($pathToFile, strlen($relativePath));
}

return $pathToFile;
Expand Down
17 changes: 17 additions & 0 deletions tests/Commands/BackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@
expect($zipFiles)->toBe($testFiles);
});

it('can backup using short relative path', function () {
config()->set('backup.backup.source.files.include', [$this->getStubDirectory()]);
config()->set('backup.backup.source.files.relative_path', '/stubs');

$this->artisan('backup:run --only-files')->assertExitCode(0);

$zipFile = '';
$zip = new ZipArchive();
$zip->open(Storage::disk('local')->path($this->expectedZipPath));
if ($zip->numFiles) {
$zipFile = $zip->statIndex(0)['name'];
}
$zip->close();

expect($zipFile)->toStartWith(ltrim($this->getStubDirectory(), DIRECTORY_SEPARATOR));
});

it('excludes the temporary directory from the backup', function () {
$tempDirectoryPath = storage_path('app/backup-temp/temp');

Expand Down

0 comments on commit 3a86fbc

Please sign in to comment.