Merge pull request #8714 from nextcloud/8705

Check if the cached js file exists
This commit is contained in:
Morris Jobke 2018-03-07 14:45:43 +01:00 committed by GitHub
commit 8d865483f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -104,13 +104,20 @@ class JSCombiner {
* @return bool * @return bool
*/ */
protected function isCached($fileName, ISimpleFolder $folder) { protected function isCached($fileName, ISimpleFolder $folder) {
$fileName = str_replace('.json', '.js', $fileName) . '.deps'; $fileName = str_replace('.json', '.js', $fileName);
if (!$folder->fileExists($fileName)) {
return false;
}
$fileName = $fileName . '.deps';
try { try {
$deps = $this->depsCache->get($folder->getName() . '-' . $fileName); $deps = $this->depsCache->get($folder->getName() . '-' . $fileName);
if ($deps === null || $deps === '') { if ($deps === null || $deps === '') {
$depFile = $folder->getFile($fileName); $depFile = $folder->getFile($fileName);
$deps = $depFile->getContent(); $deps = $depFile->getContent();
} }
// check again // check again
if ($deps === null || $deps === '') { if ($deps === null || $deps === '') {
$this->logger->info('JSCombiner: deps file empty: ' . $fileName); $this->logger->info('JSCombiner: deps file empty: ' . $fileName);

View File

@ -187,6 +187,10 @@ class JSCombinerTest extends \Test\TestCase {
$fileDeps->expects($this->once())->method('getContent')->willReturn('{}'); $fileDeps->expects($this->once())->method('getContent')->willReturn('{}');
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$folder->method('getFile') $folder->method('getFile')
->will($this->returnCallback(function($path) use ($file, $fileDeps) { ->will($this->returnCallback(function($path) use ($file, $fileDeps) {
if ($path === 'combine.js') { if ($path === 'combine.js') {
@ -196,6 +200,7 @@ class JSCombinerTest extends \Test\TestCase {
if ($path === 'combine.js.deps') { if ($path === 'combine.js.deps') {
return $fileDeps; return $fileDeps;
} }
$this->fail(); $this->fail();
})); }));
@ -221,6 +226,9 @@ class JSCombinerTest extends \Test\TestCase {
->willReturn($folder); ->willReturn($folder);
$folder->method('getName') $folder->method('getName')
->willReturn('awesomeapp'); ->willReturn('awesomeapp');
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class); $file = $this->createMock(ISimpleFile::class);
@ -263,6 +271,9 @@ class JSCombinerTest extends \Test\TestCase {
public function testIsCachedWithNotExistingFile() { public function testIsCachedWithNotExistingFile() {
$fileName = 'combine.json'; $fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class); $folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class); $file = $this->createMock(ISimpleFile::class);
$folder->method('getFile') $folder->method('getFile')
->with('combine.js.deps') ->with('combine.js.deps')
@ -278,6 +289,9 @@ class JSCombinerTest extends \Test\TestCase {
public function testIsCachedWithOlderMtime() { public function testIsCachedWithOlderMtime() {
$fileName = 'combine.json'; $fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class); $folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class); $file = $this->createMock(ISimpleFile::class);
$folder->method('getFile') $folder->method('getFile')
->with('combine.js.deps') ->with('combine.js.deps')
@ -293,6 +307,9 @@ class JSCombinerTest extends \Test\TestCase {
public function testIsCachedWithoutContent() { public function testIsCachedWithoutContent() {
$fileName = 'combine.json'; $fileName = 'combine.json';
$folder = $this->createMock(ISimpleFolder::class); $folder = $this->createMock(ISimpleFolder::class);
$folder->method('fileExists')
->with('combine.js')
->willReturn(true);
$file = $this->createMock(ISimpleFile::class); $file = $this->createMock(ISimpleFile::class);
$folder->method('getFile') $folder->method('getFile')
->with('combine.js.deps') ->with('combine.js.deps')