Skip to content

Commit

Permalink
Merge pull request #110 from Laravel-Backpack/move-files-to-extract-t…
Browse files Browse the repository at this point in the history
…o-temporary-folder

Move files to temporary folder before extraction
  • Loading branch information
pxpm authored Feb 20, 2024
2 parents 224e9ed + 59d5dce commit 9ecbeaf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/BassetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,21 @@ public function bassetArchive(string $asset, string $output): StatusEnum
}

$tempDir = $this->unarchiver->getTemporaryDirectoryPath();
$this->unarchiver->unarchiveFile($file, $tempDir);
$fileName = basename($file);

// internalize all files in the folder
// first copy the file to the temporary folder, that way we are sure that the folder is writable
File::copy($file, $tempDir.$fileName);
$this->unarchiver->unarchiveFile($tempDir.$fileName, $tempDir);

// internalize all files in the folder except the zip file itself
foreach (File::allFiles($tempDir) as $file) {
$this->disk->put("$path/{$file->getRelativePathName()}", File::get($file), 'public');
if ($file->getRelativePathName() !== $fileName) {
$this->disk->put("$path/{$file->getRelativePathName()}", File::get($file), 'public');
}
}

// delete the whole temporary folder
File::delete($tempDir);

$this->cacheMap->addAsset($asset);

return $this->loader->finish(StatusEnum::INTERNALIZED);
Expand Down

0 comments on commit 9ecbeaf

Please sign in to comment.