diff --git a/controllers/Download.php b/controllers/Download.php index 94e10a59..b5de5496 100644 --- a/controllers/Download.php +++ b/controllers/Download.php @@ -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)