mirror of
https://github.com/klaussilveira/gitlist.git
synced 2026-02-20 21:47:32 +01:00
Refactored archive handling. Fixes #413
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user