[GH-ISSUE #324] Support locking a file to prevent from deleting/moving #171

Closed
opened 2026-04-08 16:50:51 +03:00 by zhus · 10 comments
Owner

Originally created by @jessehu on GitHub (Dec 21, 2023).
Original GitHub issue: https://github.com/sigoden/dufs/issues/324

Originally created by @jessehu on GitHub (Dec 21, 2023). Original GitHub issue: https://github.com/sigoden/dufs/issues/324
zhus closed this issue 2026-04-08 16:50:51 +03:00
Author
Owner

@sigoden commented on GitHub (Dec 21, 2023):

If you don't want to edit the file, you may set read-only permissions.
Dufs allow you control the permissions of files or directorie with --auth.

<!-- gh-comment-id:1865810984 --> @sigoden commented on GitHub (Dec 21, 2023): If you don't want to edit the file, you may set read-only permissions. Dufs allow you control the permissions of files or directorie with `--auth`.
Author
Owner

@jessehu commented on GitHub (Dec 21, 2023):

do you mean setting read-only permission for a single file via 'chmod 400'? Can it be done on dufs UI?

<!-- gh-comment-id:1865827929 --> @jessehu commented on GitHub (Dec 21, 2023): do you mean setting read-only permission for a single file via 'chmod 400'? Can it be done on dufs UI?
Author
Owner

@sigoden commented on GitHub (Dec 21, 2023):

Have you read the dufs readme? dufs can set permissions for paths. @jessehu

image

<!-- gh-comment-id:1865833450 --> @sigoden commented on GitHub (Dec 21, 2023): Have you read the dufs readme? dufs can set permissions for paths. @jessehu ![image](https://github.com/sigoden/dufs/assets/4012553/80368e4d-ea13-4811-9027-7f62c8122eb9)
Author
Owner

@jessehu commented on GitHub (Dec 21, 2023):

This solution requires restarting dufs for each file to be locked and unlocked. Not easy to use.

<!-- gh-comment-id:1865862166 --> @jessehu commented on GitHub (Dec 21, 2023): This solution requires restarting dufs for each file to be locked and unlocked. Not easy to use.
Author
Owner

@sigoden commented on GitHub (Dec 21, 2023):

dufs is a stateless file server and does not support file dynamic locking.

<!-- gh-comment-id:1865891785 --> @sigoden commented on GitHub (Dec 21, 2023): dufs is a stateless file server and does not support file dynamic locking.
Author
Owner

@jessehu commented on GitHub (Dec 21, 2023):

I see. Just wondering if it can be archieved by:

  1. Is it possible to ignore deleting a file if its file mode is read only ? Also set file mode to 400 when locking this file on dufs UI.
  2. or create/delete a <filename>.lock file when locking/unlocking this file on dufs UI?
<!-- gh-comment-id:1865895855 --> @jessehu commented on GitHub (Dec 21, 2023): I see. Just wondering if it can be archieved by: 1. Is it possible to ignore deleting a file if its file mode is read only ? Also set file mode to 400 when locking this file on dufs UI. 2. or create/delete a `<filename>.lock` file when locking/unlocking this file on dufs UI?
Author
Owner

@sigoden commented on GitHub (Dec 21, 2023):

The only way I recommend to protect files is through auth. Other methods are error prone.

<!-- gh-comment-id:1865903045 --> @sigoden commented on GitHub (Dec 21, 2023): The only way I recommend to protect files is through auth. Other methods are error prone.
Author
Owner

@jessehu commented on GitHub (Dec 22, 2023):

Thanks. I tried the solution 1 and works well:
图片

Code change: e12f97e92f

<!-- gh-comment-id:1867081996 --> @jessehu commented on GitHub (Dec 22, 2023): Thanks. I tried the solution 1 and works well: ![图片](https://github.com/sigoden/dufs/assets/10006/e5b61fa6-95e2-4b19-891c-662dbf7cc8ca) Code change: https://github.com/sigoden/dufs/commit/e12f97e92f8e79aa0e8032c2a317db06887e65a7
Author
Owner

@sigoden commented on GitHub (Dec 22, 2023):

This solution is also error prone.

Here is the doc for std::fs::Permissions:
image

Permissions do not check ACLs. If the file permissions are "-rw-r--r-- ubuntu web..." and you run dufs in the "web" group, you may think dufs will think the file is readonly and return 403, but it's wrong, becase permissions().readonly() returns false and dufs will return 500.

There is no easy way to determine whether a file is truely readonly for a process.

<!-- gh-comment-id:1867103120 --> @sigoden commented on GitHub (Dec 22, 2023): This solution is also error prone. Here is the doc for `std::fs::Permissions`: ![image](https://github.com/sigoden/dufs/assets/4012553/b6f85f45-8ed4-41e3-ac77-24a246af7eea) Permissions do not check ACLs. If the file permissions are "-rw-r--r-- ubuntu web..." and you run dufs in the "web" group, you may think dufs will think the file is readonly and return 403, but it's wrong, becase `permissions().readonly()` returns false and dufs will return 500. There is no easy way to determine whether a file is truely readonly for a process.
Author
Owner

@jessehu commented on GitHub (Dec 22, 2023):

Yup, it depends on which user used to run dufs, and this is controlled by the user who runs dufs.

<!-- gh-comment-id:1867107267 --> @jessehu commented on GitHub (Dec 22, 2023): Yup, it depends on which user used to run dufs, and this is controlled by the user who runs dufs.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sigoden/dufs#171