Let tar change working directory to assets directory.

This prevents edge cases where files are not found, while ensuring
the archive does not contain the system directory hierarchy.
This commit is contained in:
Aaron van Geffen 2020-03-01 17:07:10 +01:00
parent 354e54a0af
commit 1b7e83e11e

View File

@ -29,22 +29,16 @@ class Download
exit; exit;
} }
private function exportAlbum($album) private function exportAlbum(Tag $album)
{ {
$files = []; $files = [];
$album_ids = array_merge([$album->id_tag], $this->getChildAlbumIds($album->id_tag)); $album_ids = array_merge([$album->id_tag], $this->getChildAlbumIds($album->id_tag));
foreach($album_ids as $album_id) foreach($album_ids as $album_id)
{ {
$iterator = AssetIterator::getByOptions( $iterator = AssetIterator::getByOptions(['id_tag' => $album_id]);
[ while ($asset = $iterator->next())
'id_tag' => $album_id $files[] = join(DIRECTORY_SEPARATOR, [$asset->getSubdir(), $asset->getFilename()]);
]
);
while($asset = $iterator->Next())
{
$files[] = join(DIRECTORY_SEPARATOR, ['.', $asset->getSubdir(), $asset->getFilename()]);
}
} }
$descriptorspec = [ $descriptorspec = [
@ -52,7 +46,7 @@ class Download
1 => ['pipe', 'w'], 1 => ['pipe', 'w'],
]; ];
$command = 'tar --null -cf - -T -'; $command = 'tar -cf - -C ' . escapeshellarg(ASSETSDIR) . ' --null -T -';
$proc = proc_open($command, $descriptorspec, $pipes, ASSETSDIR); $proc = proc_open($command, $descriptorspec, $pipes, ASSETSDIR);