Skip to content

Commit 2200f6a

Browse files
test(storage): cover removal of directory symlinks
Verify that deleting a directory symlink through rmdir or unlink removes only the link while preserving the target directory and its contents. Assisted-by: Copilot:gpt-5.6-sol Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent d6747c3 commit 2200f6a

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/lib/Files/Storage/LocalTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,50 @@ public function testDisallowSymlinksInsideDatadir(): void {
102102
$this->addToAssertionCount(1);
103103
}
104104

105+
public static function directorySymlinkRemovalProvider(): array {
106+
return [
107+
'rmdir' => ['rmdir'],
108+
'unlink' => ['unlink'],
109+
];
110+
}
111+
112+
#[\PHPUnit\Framework\Attributes\DataProvider('directorySymlinkRemovalProvider')]
113+
public function testRemovingDirectorySymlinkPreservesTarget(string $operation): void {
114+
$targetPath = $this->tmpDir . 'target';
115+
$linkPath = $this->tmpDir . 'link';
116+
117+
$this->assertTrue($this->instance->mkdir('target'));
118+
$this->assertSame(
119+
strlen('target contents'),
120+
$this->instance->file_put_contents('target/file.txt', 'target contents'),
121+
);
122+
123+
if (!@symlink($targetPath, $linkPath)) {
124+
$this->markTestSkipped('Failed to create directory symlink');
125+
}
126+
127+
$this->assertTrue(is_link($linkPath));
128+
$this->assertTrue($this->instance->$operation('link'));
129+
130+
$this->assertFalse(
131+
is_link($linkPath),
132+
'The symbolic link should be removed',
133+
);
134+
$this->assertDirectoryExists(
135+
$targetPath,
136+
'The target directory should be preserved',
137+
);
138+
$this->assertFileExists(
139+
$targetPath . '/file.txt',
140+
'Files inside the target directory should be preserved',
141+
);
142+
$this->assertSame(
143+
'target contents',
144+
file_get_contents($targetPath . '/file.txt'),
145+
'The target file contents should remain unchanged',
146+
);
147+
}
148+
105149
public function testWriteUmaskFilePutContents(): void {
106150
$oldMask = umask(0333);
107151
$this->instance->file_put_contents('test.txt', 'sad');

0 commit comments

Comments
 (0)