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

removePathForcibly can affect the permissions of files outside the path being deleted #135

Closed
joeyh opened this issue May 2, 2022 · 2 comments
Labels
type: a-bug The described behavior is not working as intended.

Comments

@joeyh
Copy link

joeyh commented May 2, 2022

When a file is a hard link, removePathForcibly will modify the permissions of files outside the directory being deleted:

joey@darkstar:~/tmp>mkdir test
joey@darkstar:~/tmp>cd test
joey@darkstar:~/tmp/test>l
joey@darkstar:~/tmp/test>mkdir foo
joey@darkstar:~/tmp/test>mkdir bar
joey@darkstar:~/tmp/test>echo hi > bar/f
joey@darkstar:~/tmp/test>chmod 400 bar/f
joey@darkstar:~/tmp/test>ln bar/f foo/f
joey@darkstar:~/tmp/test>ghci
GHCi, version 8.8.4: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/joey/.etc/.ghci
ghci> import System.Directory
ghci> removePathForcibly "foo"
ghci> 
Leaving GHCi.
joey@darkstar:~/tmp/test>ls -l bar
total 4
-rwx------ 1 joey joey 3 May  2 13:34 f*

I doubt that changing the permissions of a file is ever necessary to let it be deleted.

If it only changed the permissions of directories, which can be necessary, it would avoid this problem.

@joeyh
Copy link
Author

joeyh commented May 2, 2022

The haddock does actually warn about this, but in my experience this is easy to miss.

-- Unlike other removal functions, this function will also attempt to delete
-- files marked as read-only or otherwise made unremovable due to permissions.
-- As a result, if the removal is incomplete, the permissions or attributes on
-- the remaining files may be altered. If there are hard links in the
-- directory, then permissions on all related hard links may be altered.

@Rufflewind
Copy link
Member

I doubt that changing the permissions of a file is ever necessary to let it be deleted.

On Windows, read-only files cannot be removed unless the read-only attribute is removed.

One possible workaround might be to only modify permissions of files on Windows platforms, at the cost of additional complexity.

Rufflewind added a commit to Rufflewind/directory that referenced this issue Sep 8, 2022
Rufflewind added a commit to Rufflewind/directory that referenced this issue Sep 8, 2022
@Rufflewind Rufflewind added the type: a-bug The described behavior is not working as intended. label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: a-bug The described behavior is not working as intended.
Projects
None yet
Development

No branches or pull requests

2 participants