Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 568eb1b

Browse files
committed
Another angle
1 parent 60a1232 commit 568eb1b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Symfony/Component/AssetMapper/ImportMap/RemotePackageStorage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function save(ImportMapEntry $entry, string $contents): void
6363
} catch (IOException $e) {
6464
throw new RuntimeException(\sprintf('Failed to write file "%s".', $vendorPath), 0, $e);
6565
}
66+
67+
if (!is_file($vendorPath) || !is_writable($vendorPath)) {
68+
throw new RuntimeException(\sprintf('Failed to write file "%s".', $vendorPath));
69+
}
6670
}
6771

6872
public function saveExtraFile(ImportMapEntry $entry, string $extraFilename, string $contents): void
@@ -78,6 +82,10 @@ public function saveExtraFile(ImportMapEntry $entry, string $extraFilename, stri
7882
} catch (IOException $e) {
7983
throw new RuntimeException(\sprintf('Failed to write file "%s".', $vendorPath), 0, $e);
8084
}
85+
86+
if (!is_file($vendorPath) || !is_writable($vendorPath)) {
87+
throw new RuntimeException(\sprintf('Failed to write file "%s".', $vendorPath));
88+
}
8189
}
8290

8391
/**

src/Symfony/Component/AssetMapper/Tests/ImportMap/RemotePackageStorageTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,15 @@ public function testSaveThrowsWhenFailing()
4646
$vendorDir = self::$writableRoot.'/assets/acme/vendor';
4747
$this->filesystem->mkdir($vendorDir.'/module_specifier');
4848
$this->filesystem->touch($vendorDir.'/module_specifier/module_specifier.index.js');
49-
$this->filesystem->chmod($vendorDir.'/module_specifier', 0555);
49+
$this->filesystem->chmod($vendorDir.'/module_specifier/module_specifier.index.js', 0555);
5050

5151
$storage = new RemotePackageStorage($vendorDir);
5252
$entry = ImportMapEntry::createRemote('foo', ImportMapType::JS, '/does/not/matter', '1.0.0', 'module_specifier', false);
5353

5454
$this->expectException(\RuntimeException::class);
5555
$this->expectExceptionMessage('Failed to write file "'.$vendorDir.'/module_specifier/module_specifier.index.js');
5656

57-
try {
58-
$storage->save($entry, 'any content');
59-
} finally {
60-
$this->filesystem->chmod($vendorDir.'/module_specifier/', 0777);
61-
}
57+
$storage->save($entry, 'any content');
6258
}
6359

6460
public function testIsDownloaded()

0 commit comments

Comments
 (0)