Skip to content

Commit 6e1a5c8

Browse files
authored
Fix "Text file busy" error when call deleteDirectory (#48422)
1 parent c091302 commit 6e1a5c8

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/Illuminate/Filesystem/Filesystem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ public function deleteDirectory($directory, $preserve = false)
749749
}
750750
}
751751

752+
unset($items);
753+
752754
if (! $preserve) {
753755
@rmdir($directory);
754756
}

tests/Integration/Filesystem/FilesystemTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,17 @@ public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnIsFile
7070
clearstatcache(true, $this->stubFile);
7171
$this->assertFalse(File::isFile($this->stubFile));
7272
}
73+
74+
public function testItCanDeleteDirectoryViaFilesystem()
75+
{
76+
if (! File::exists(storage_path('app/public/testdir'))) {
77+
File::makeDirectory(storage_path('app/public/testdir'));
78+
}
79+
80+
$this->assertTrue(File::exists(storage_path('app/public/testdir')));
81+
82+
File::deleteDirectory(storage_path('app/public/testdir'));
83+
84+
$this->assertFalse(File::exists(storage_path('app/public/testdir')));
85+
}
7386
}

tests/Integration/Filesystem/StorageTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,19 @@ public function testConditionable()
7979
Storage::disk('public')->assertMissing('StardewTaylor.png');
8080
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
8181
}
82+
83+
public function testItCanDeleteDirectoryViaStorage()
84+
{
85+
if (! Storage::disk('public')->exists('testdir')) {
86+
Storage::disk('public')->makeDirectory('testdir');
87+
}
88+
89+
Storage::disk('public')->assertExists('testdir');
90+
$this->assertTrue(Storage::disk('public')->exists('testdir'));
91+
92+
Storage::disk('public')->deleteDirectory('testdir');
93+
94+
Storage::disk('public')->assertMissing('testdir');
95+
$this->assertFalse(Storage::disk('public')->exists('testdir'));
96+
}
8297
}

0 commit comments

Comments
 (0)