Use $_SESSION['current_export'] to prevent simultaneous exports.

This commit is contained in:
Aaron van Geffen 2020-03-11 18:57:31 +01:00
parent c7d3b9c3d1
commit bd1ca8d18c

View File

@ -22,7 +22,7 @@ class Download
$album = Tag::fromId($tag);
if (isset($_SESSION['current_export']))
throw new UserFacingException('An export of "' . $tag->tag . '" is ongoing. Please try again later.');
throw new UserFacingException('You can only export one album at the same time. Please wait until the other download finishes, or try again later.');
// So far so good?
$this->exportAlbum($album);
@ -46,6 +46,15 @@ class Download
1 => ['pipe', 'w'], // STDOUT
];
// Prevent simultaneous exports.
$_SESSION['current_export'] = $album->id_tag;
// Allow new exports if the connection is terminated unexpectedly (e.g. when a user aborts a download).
register_shutdown_function(function() {
if (isset($_SESSION['current_export']))
unset($_SESSION['current_export']);
});
$command = 'tar -cf - -C ' . escapeshellarg(ASSETSDIR) . ' --null -T -';
$proc = proc_open($command, $descriptorspec, $pipes, ASSETSDIR);
@ -92,6 +101,9 @@ class Download
fclose($pipes[1]);
proc_close($proc);
// Allow new exports from this point onward.
unset($_SESSION['current_export']);
}
private function getChildAlbumIds($parent_id)