From 95d0c646f9f64624f37290b44fc68e32b209407b Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 25 Jan 2017 18:20:41 -0500 Subject: [PATCH] Require packs to be a tarball --- app/Repositories/ServiceRepository/Pack.php | 15 +++++---------- .../views/admin/services/packs/edit.blade.php | 2 +- .../views/admin/services/packs/new.blade.php | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/Repositories/ServiceRepository/Pack.php b/app/Repositories/ServiceRepository/Pack.php index ae68c1a6b..c5dee34a4 100644 --- a/app/Repositories/ServiceRepository/Pack.php +++ b/app/Repositories/ServiceRepository/Pack.php @@ -66,11 +66,8 @@ class Pack throw new DisplayException('The file provided does not appear to be valid.'); } - if (! in_array($data['file_upload']->getMimeType(), [ - 'application/zip', - 'application/gzip', - ])) { - throw new DisplayException('The file provided does not meet the required filetypes of application/zip or application/gzip.'); + if ($data['file_upload']->getMimeType() !== 'application/gzip') { + throw new DisplayException('The file provided does not meet the required filetype of application/gzip.'); } } @@ -95,8 +92,7 @@ class Pack Storage::makeDirectory('packs/' . $pack->uuid); if (isset($data['file_upload'])) { - $filename = ($data['file_upload']->getMimeType() === 'application/zip') ? 'archive.zip' : 'archive.tar.gz'; - $data['file_upload']->storeAs('packs/' . $pack->uuid, $filename); + $data['file_upload']->storeAs('packs/' . $pack->uuid, 'archive.tar.gz'); } DB::commit(); @@ -132,10 +128,9 @@ class Pack throw new DisplayException('The uploaded archive was unable to be opened.'); } - $isZip = $zip->locateName('archive.zip'); $isTar = $zip->locateName('archive.tar.gz'); - if ($zip->locateName('import.json') === false || ($isZip === false && $isTar === false)) { + if (! $zip->locateName('import.json') || ! $isTar) { throw new DisplayException('This contents of the provided archive were in an invalid format.'); } @@ -156,7 +151,7 @@ class Pack ]); $pack = Models\ServicePack::findOrFail($id); - if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), ($isZip === false) ? 'archive.tar.gz' : 'archive.zip')) { + if (! $zip->extractTo(storage_path('app/packs/' . $pack->uuid), 'archive.tar.gz')) { $pack->delete(); throw new DisplayException('Unable to extract the archive file to the correct location.'); } diff --git a/resources/views/admin/services/packs/edit.blade.php b/resources/views/admin/services/packs/edit.blade.php index 0c05d4f99..0cdd80705 100644 --- a/resources/views/admin/services/packs/edit.blade.php +++ b/resources/views/admin/services/packs/edit.blade.php @@ -175,7 +175,7 @@ @endforeach -

If you wish to modify or upload a new file it should be uploaded to {{ storage_path('app/packs/' . $pack->uuid) }} as either archive.zip or archive.tar.gz.

+

If you wish to modify or upload a new file it should be uploaded to {{ storage_path('app/packs/' . $pack->uuid) }} as archive.tar.gz.

diff --git a/resources/views/admin/services/packs/new.blade.php b/resources/views/admin/services/packs/new.blade.php index c31f1c77e..7a5be8f47 100644 --- a/resources/views/admin/services/packs/new.blade.php +++ b/resources/views/admin/services/packs/new.blade.php @@ -150,8 +150,8 @@
- -

This package file must either be a .zip or .tar.gz archive of files to use for either building or running this pack.

If your file is larger than 20MB we recommend uploading it using SFTP. Once you have added this pack to the system, a path will be provided where you should upload the file. + +

This package file must be a .tar.gz archive of files to use for either building or running this pack.

If your file is larger than 20MB we recommend uploading it using SFTP. Once you have added this pack to the system, a path will be provided where you should upload the file. This server is currently configured with the following limits: upload_max_filesize={{ ini_get('upload_max_filesize') }} and post_max_size={{ ini_get('post_max_size') }}. If your file is larger than either of those values this request will fail.