Skip to content

fix(storage): Unlink symlink instead of deleting target content and link #53447

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fxprunayre
Copy link

Summary

Nextcloud allow following symlink (https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#localstorage-allowsymlinks) but removal of symlink remove files in the target of the symlink and fail to remove the link returning an error.

Using the following structure:

.
├── afolder
│   └── test.txt
├── alink -> afolder
└── welcome.txt

created with:

mkdir afolder
touch afolder/test.txt
ln -s afolder alink

Current

After deletion of alink symbolic link, the content of afolder is removed, the link also and an error is reported.

{
  "method":"DELETE",
  "url":"/remote.php/dav/files/admin/alink",
  "message":"rmdir(/data/dev/nextcloud/data/admin/files/alink): Not a directory at /data/dev/nextcloud/lib/private/Files/Storage/Local.php#128"
}

Results is:

.
├── afolder
└── welcome.txt

Screenshot from 2025-06-12 08-29-22

After

If the resource to be deleted is a link, unlink it (and preserve link target content).

.
├── afolder
│   └── test.txt
└── welcome.txt

Screenshot from 2025-06-12 08-32-20

Todo

Quite new to the Nextcloud codebase, any pointer to a test related to symlink is welcomed.

Checklist

@fxprunayre fxprunayre requested a review from a team as a code owner June 12, 2025 07:14
@fxprunayre fxprunayre requested review from ArtificialOwl, yemkareems and sorbaugh and removed request for a team June 12, 2025 07:14
Nextcloud allow following symlink (https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#localstorage-allowsymlinks) but removal of symlink remove files in the target of the symlink and fail to remove the link returning an error.

Using the following structure:

```
.
├── afolder
│   └── test.txt
├── alink -> afolder
└── welcome.txt
```

created with:

```bash
mkdir afolder
touch afolder/test.txt
ln -s afolder alink
```

After deletion of `alink` symbolic link, the content of `afolder` is removed, the link also and an error is reported.

```json
{
  "method":"DELETE",
  "url":"/remote.php/dav/files/admin/alink",
  "message":"rmdir(/data/dev/nextcloud/data/admin/files/alink): Not a directory at /data/dev/nextcloud/lib/private/Files/Storage/Local.php#128"
}
```

Results is:
```
.
├── afolder
└── welcome.txt
```

If the resource to be deleted is a link, unlink it (and preserve link target content).

```
.
├── afolder
│   └── test.txt
└── welcome.txt
```

Signed-off-by: Francois Prunayre <[email protected]>
@fxprunayre fxprunayre force-pushed the fix/symlink-removal branch from 36ca73a to 9fb276c Compare June 12, 2025 09:41
Copy link
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant