Skip to content

Commit 8d86548

Browse files
authored
Merge pull request #8714 from nextcloud/8705
Check if the cached js file exists
2 parents d1aa96f + 448a5e5 commit 8d86548

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/private/Template/JSCombiner.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,20 @@ public function process($root, $file, $app) {
104104
* @return bool
105105
*/
106106
protected function isCached($fileName, ISimpleFolder $folder) {
107-
$fileName = str_replace('.json', '.js', $fileName) . '.deps';
107+
$fileName = str_replace('.json', '.js', $fileName);
108+
109+
if (!$folder->fileExists($fileName)) {
110+
return false;
111+
}
112+
113+
$fileName = $fileName . '.deps';
108114
try {
109115
$deps = $this->depsCache->get($folder->getName() . '-' . $fileName);
110116
if ($deps === null || $deps === '') {
111117
$depFile = $folder->getFile($fileName);
112118
$deps = $depFile->getContent();
113119
}
120+
114121
// check again
115122
if ($deps === null || $deps === '') {
116123
$this->logger->info('JSCombiner: deps file empty: ' . $fileName);

tests/lib/Template/JSCombinerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public function testProcessCachedFile() {
187187

188188
$fileDeps->expects($this->once())->method('getContent')->willReturn('{}');
189189

190+
$folder->method('fileExists')
191+
->with('combine.js')
192+
->willReturn(true);
193+
190194
$folder->method('getFile')
191195
->will($this->returnCallback(function($path) use ($file, $fileDeps) {
192196
if ($path === 'combine.js') {
@@ -196,6 +200,7 @@ public function testProcessCachedFile() {
196200
if ($path === 'combine.js.deps') {
197201
return $fileDeps;
198202
}
203+
199204
$this->fail();
200205
}));
201206

@@ -221,6 +226,9 @@ public function testProcessCachedFileMemcache() {
221226
->willReturn($folder);
222227
$folder->method('getName')
223228
->willReturn('awesomeapp');
229+
$folder->method('fileExists')
230+
->with('combine.js')
231+
->willReturn(true);
224232

225233
$file = $this->createMock(ISimpleFile::class);
226234

@@ -263,6 +271,9 @@ public function testIsCachedNoDepsFile() {
263271
public function testIsCachedWithNotExistingFile() {
264272
$fileName = 'combine.json';
265273
$folder = $this->createMock(ISimpleFolder::class);
274+
$folder->method('fileExists')
275+
->with('combine.js')
276+
->willReturn(true);
266277
$file = $this->createMock(ISimpleFile::class);
267278
$folder->method('getFile')
268279
->with('combine.js.deps')
@@ -278,6 +289,9 @@ public function testIsCachedWithNotExistingFile() {
278289
public function testIsCachedWithOlderMtime() {
279290
$fileName = 'combine.json';
280291
$folder = $this->createMock(ISimpleFolder::class);
292+
$folder->method('fileExists')
293+
->with('combine.js')
294+
->willReturn(true);
281295
$file = $this->createMock(ISimpleFile::class);
282296
$folder->method('getFile')
283297
->with('combine.js.deps')
@@ -293,6 +307,9 @@ public function testIsCachedWithOlderMtime() {
293307
public function testIsCachedWithoutContent() {
294308
$fileName = 'combine.json';
295309
$folder = $this->createMock(ISimpleFolder::class);
310+
$folder->method('fileExists')
311+
->with('combine.js')
312+
->willReturn(true);
296313
$file = $this->createMock(ISimpleFile::class);
297314
$folder->method('getFile')
298315
->with('combine.js.deps')

0 commit comments

Comments
 (0)