From bd69511810ba92a7e45f4e1a48474234dcaa746d Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Sat, 17 May 2014 13:12:29 -0300 Subject: [PATCH] Refactored archive handling. Fixes #413 --- src/GitList/Application.php | 8 ++++++++ src/GitList/Controller/TreeController.php | 14 ++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/GitList/Application.php b/src/GitList/Application.php index 8259da1..7fda4de 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -9,6 +9,7 @@ use GitList\Provider\GitServiceProvider; use GitList\Provider\RepositoryUtilServiceProvider; use GitList\Provider\ViewUtilServiceProvider; use GitList\Provider\RoutingUtilServiceProvider; +use Symfony\Component\Filesystem\Filesystem; /** * GitList application. @@ -77,6 +78,13 @@ class Application extends SilexApplication 'message' => $e->getMessage(), )); }); + + $this->finish(function () use ($app, $config) { + if (!$config->get('app', 'cache')) { + $fs = new Filesystem(); + $fs->remove($app['cache.archives']); + } + }); } public function formatDate($date) diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 6e88e05..7d1369c 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -4,8 +4,8 @@ namespace GitList\Controller; use Silex\Application; use Silex\ControllerProviderInterface; -use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\BinaryFileResponse; class TreeController implements ControllerProviderInterface { @@ -71,9 +71,6 @@ class TreeController implements ControllerProviderInterface ->assert('branch', $app['util.routing']->getBranchRegex()) ->bind('search'); - - # Intentionally before next statement, because order appears - # to be important, and the other statement got precedence previously. $route->get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) { $repository = $app['git']->getRepositoryFromName($app['git.repos'], $repo); @@ -94,14 +91,7 @@ class TreeController implements ControllerProviderInterface $repository->createArchive($tree, $file, $format); } - return new StreamedResponse(function () use ($file) { - readfile($file); - }, 200, array( - 'Content-type' => ('zip' === $format) ? 'application/zip' : 'application/x-tar', - 'Content-Description' => 'File Transfer', - 'Content-Disposition' => 'attachment; filename="'.$repo.'-'.substr($tree, 0, 6).'.'.$format.'"', - 'Content-Transfer-Encoding' => 'binary', - )); + return new BinaryFileResponse($file); })->assert('format', '(zip|tar)') ->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('branch', $app['util.routing']->getBranchRegex())