Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_exists() returns false for symlinks with missing targets #346

Open
dshoreman opened this issue Feb 17, 2021 · 0 comments
Open

file_exists() returns false for symlinks with missing targets #346

dshoreman opened this issue Feb 17, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@dshoreman
Copy link
Owner

Background

If a symlink is passed and its target does not exist, PHP's file_exists function will return false regardless of whether the symlink itself exists at the given path or not.

The Issue

Currently we short-circuit when PHP claims the "file" doesn't exist:

public function delete(string $path): array
{
$remove = is_dir($path) ? 'rmdir' : 'unlink';
$error = ['code' => 500, 'msg' => 'Failed removing' . $path];
if (!file_exists($path)) {
return ['error' => null];
}
if (!is_writable($path)) {
return ['error' => ['code' => 403, 'msg' => 'No permission to write path']];
}
return ['error' => $remove($path) ? null : $error];
}

...meaning if we attempt to delete a symlink and its target has already been removed, it's not possible to remove the symlink without first pointing it to a file that exists (or creating the file it references).


We'll need another test (see below), but it may be necessary to check is_link() first so that special treatment can be given.

Theoretical Test

/** @test */
public function can_delete_symlink_when_target_is_missing(): void
{
    $link = 'test-skel/some-symlink';
    $target = 'test-skel/non-existent-path';

    createSymlink($link, $target);
    deleteWithFileManager($link);
    assertDoesNotExist($link);
}
@dshoreman dshoreman added the bug Something isn't working label Feb 17, 2021
@dshoreman dshoreman added this to To do in File Manager via automation Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
File Manager
  
To do
Development

No branches or pull requests

1 participant