Skip to content

Commit 8c293f9

Browse files
authored
[8.x] Run clearstatcache after deleting file and asserting Storage using exists/missing (#40257)
* wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent ab29010 commit 8c293f9

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

src/Illuminate/Filesystem/Filesystem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ public function delete($paths)
282282

283283
foreach ($paths as $path) {
284284
try {
285-
if (! @unlink($path)) {
285+
if (@unlink($path)) {
286+
clearstatcache(false, $path);
287+
} else {
286288
$success = false;
287289
}
288290
} catch (ErrorException $e) {

src/Illuminate/Filesystem/FilesystemAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function __construct(FilesystemInterface $driver)
7272
*/
7373
public function assertExists($path, $content = null)
7474
{
75+
clearstatcache();
76+
7577
$paths = Arr::wrap($path);
7678

7779
foreach ($paths as $path) {
@@ -101,6 +103,8 @@ public function assertExists($path, $content = null)
101103
*/
102104
public function assertMissing($path)
103105
{
106+
clearstatcache();
107+
104108
$paths = Arr::wrap($path);
105109

106110
foreach ($paths as $path) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Filesystem;
4+
5+
use Illuminate\Support\Facades\File;
6+
use Orchestra\Testbench\TestCase;
7+
use Symfony\Component\Process\Process;
8+
9+
/**
10+
* @requires OS Linux|Darwin
11+
*/
12+
class FilesystemTest extends TestCase
13+
{
14+
protected $stubFile;
15+
16+
protected function setUp(): void
17+
{
18+
$this->afterApplicationCreated(function () {
19+
File::put($file = storage_path('app/public/StardewTaylor.png'), File::get(__DIR__.'/Fixtures/StardewTaylor.png'));
20+
$this->stubFile = $file;
21+
});
22+
23+
$this->beforeApplicationDestroyed(function () {
24+
if (File::exists($this->stubFile)) {
25+
File::delete($this->stubFile);
26+
}
27+
});
28+
29+
parent::setUp();
30+
}
31+
32+
public function testItCanDeleteViaFilesystemShouldUpdatesFileExists()
33+
{
34+
$this->assertTrue(File::exists($this->stubFile));
35+
$this->assertTrue(File::isFile($this->stubFile));
36+
37+
File::delete($this->stubFile);
38+
39+
$this->assertFalse(File::exists($this->stubFile));
40+
}
41+
42+
public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnFileExistsFromDifferentProcess()
43+
{
44+
$this->assertTrue(File::exists($this->stubFile));
45+
$this->assertTrue(File::isFile($this->stubFile));
46+
47+
Process::fromShellCommandline("rm {$this->stubFile}")->run();
48+
49+
clearstatcache(true, $this->stubFile);
50+
$this->assertFalse(File::exists($this->stubFile));
51+
}
52+
53+
public function testItCanDeleteViaFilesystemShouldUpdatesIsFile()
54+
{
55+
$this->assertTrue(File::exists($this->stubFile));
56+
$this->assertTrue(File::isFile($this->stubFile));
57+
58+
File::delete($this->stubFile);
59+
60+
$this->assertFalse(File::isFile($this->stubFile));
61+
}
62+
63+
public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnIsFileFromDifferentProcess()
64+
{
65+
$this->assertTrue(File::exists($this->stubFile));
66+
$this->assertTrue(File::isFile($this->stubFile));
67+
68+
Process::fromShellCommandline("rm {$this->stubFile}")->run();
69+
70+
clearstatcache(true, $this->stubFile);
71+
$this->assertFalse(File::isFile($this->stubFile));
72+
}
73+
}
20 KB
Loading
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Filesystem;
4+
5+
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Facades\Storage;
7+
use Orchestra\Testbench\TestCase;
8+
use Symfony\Component\Process\Process;
9+
10+
/**
11+
* @requires OS Linux|Darwin
12+
*/
13+
class StorageTest extends TestCase
14+
{
15+
protected $stubFile;
16+
17+
protected function setUp(): void
18+
{
19+
$this->afterApplicationCreated(function () {
20+
File::put($file = storage_path('app/public/StardewTaylor.png'), File::get(__DIR__.'/Fixtures/StardewTaylor.png'));
21+
$this->stubFile = $file;
22+
});
23+
24+
$this->beforeApplicationDestroyed(function () {
25+
if (File::exists($this->stubFile)) {
26+
File::delete($this->stubFile);
27+
}
28+
});
29+
30+
parent::setUp();
31+
}
32+
33+
public function testItCanDeleteViaStorage()
34+
{
35+
Storage::disk('public')->assertExists('StardewTaylor.png');
36+
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));
37+
38+
Storage::disk('public')->delete('StardewTaylor.png');
39+
40+
Storage::disk('public')->assertMissing('StardewTaylor.png');
41+
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
42+
}
43+
44+
public function testItCanDeleteViaFilesystemShouldUpdatesStorage()
45+
{
46+
Storage::disk('public')->assertExists('StardewTaylor.png');
47+
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));
48+
49+
File::delete($this->stubFile);
50+
51+
Storage::disk('public')->assertMissing('StardewTaylor.png');
52+
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
53+
}
54+
55+
public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnStorageFromDifferentProcess()
56+
{
57+
Storage::disk('public')->assertExists('StardewTaylor.png');
58+
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));
59+
60+
Process::fromShellCommandline("rm {$this->stubFile}")->run();
61+
62+
clearstatcache(true, $this->stubFile);
63+
Storage::disk('public')->assertMissing('StardewTaylor.png');
64+
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
65+
}
66+
}

0 commit comments

Comments
 (0)