Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Storage/Device/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ public function deletePath(string $path): bool

foreach ($files as $file) {
if (is_dir($file)) {
$this->deletePath(\substr_replace($file, '', 0, \strlen($this->getRoot().DIRECTORY_SEPARATOR)));
$relativePath = \substr($file, \strlen($this->getRoot().DIRECTORY_SEPARATOR));
$this->deletePath($relativePath);
} else {
$this->delete($file, true);
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Storage/Device/LocalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,35 @@ public function testDeletePath()
$this->assertEquals(false, $this->object->exists($path));
$this->assertEquals(false, $this->object->exists($path2));
$this->assertEquals(false, $this->object->exists($path3));

// Test Nested Directory Structure (prevents "Directory not empty" errors)
$nestedBucket = 'nested-bucket';

// Create nested structure: nested-bucket/sub1/sub2/ with files at each level
$this->assertTrue($this->object->createDirectory($nestedBucket));
$this->assertTrue($this->object->createDirectory($nestedBucket.DIRECTORY_SEPARATOR.'sub1'));
$this->assertTrue($this->object->createDirectory($nestedBucket.DIRECTORY_SEPARATOR.'sub1'.DIRECTORY_SEPARATOR.'sub2'));

// Add files in nested directories
$rootFile = $this->object->getPath('file1.txt');
$rootFile = str_ireplace($this->object->getRoot(), $this->object->getRoot().DIRECTORY_SEPARATOR.$nestedBucket, $rootFile);
$this->assertTrue($this->object->write($rootFile, 'Content 1', 'text/plain'));

$nestedFile = $this->object->getPath('file2.txt');
$nestedFile = str_ireplace($this->object->getRoot(), $this->object->getRoot().DIRECTORY_SEPARATOR.$nestedBucket.DIRECTORY_SEPARATOR.'sub1'.DIRECTORY_SEPARATOR.'sub2', $nestedFile);
$this->assertTrue($this->object->write($nestedFile, 'Content 2', 'text/plain'));

// Verify files exist
$this->assertTrue($this->object->exists($rootFile));
$this->assertTrue($this->object->exists($nestedFile));

// Delete entire nested structure - should work without "Directory not empty" error
$this->assertTrue($this->object->deletePath($nestedBucket));

// Verify everything is deleted
$this->assertFalse($this->object->exists($rootFile));
$this->assertFalse($this->object->exists($nestedFile));
$this->assertFalse(file_exists($this->object->getRoot().DIRECTORY_SEPARATOR.$nestedBucket));
}

public function testGetFiles()
Expand Down