diff --git a/src/Tasks/Backup/Zip.php b/src/Tasks/Backup/Zip.php index b2fdf192..6e4a8ef6 100644 --- a/src/Tasks/Backup/Zip.php +++ b/src/Tasks/Backup/Zip.php @@ -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; diff --git a/tests/Commands/BackupCommandTest.php b/tests/Commands/BackupCommandTest.php index 2fd2a9eb..314c1b8b 100644 --- a/tests/Commands/BackupCommandTest.php +++ b/tests/Commands/BackupCommandTest.php @@ -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');