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

with-temp-dir can raise a AccessDeniedException exception #119

Closed
jlesquembre opened this issue Dec 19, 2023 · 3 comments · Fixed by #120
Closed

with-temp-dir can raise a AccessDeniedException exception #119

jlesquembre opened this issue Dec 19, 2023 · 3 comments · Fixed by #120

Comments

@jlesquembre
Copy link
Contributor

jlesquembre commented Dec 19, 2023

This code fails with an exception:

(fs/with-temp-dir [tmp-dir {:prefix "demo"}]
   (fs/create-dir (fs/path tmp-dir "my-dir")
                  {:posix-file-permissions "r-xr-xr-x"})
   (fs/create-file (fs/path tmp-dir "my-dir" "my-file")
                   {:posix-file-permissions "r--r--r--"}))

To delete a file, the parent directory must have the OWNER_WRITE permission.

IMO, with-temp-dir shouldn't fail in this case.

A possible solution could be to add a flag to delete-tree (:force??), to set the OWNER_WRITE permission in :pre-visit-dir, and then update with-temp-dir to invoke it with the flag set to true.

If it makes sense to you, I could open a PR.

@borkdude
Copy link
Contributor

Is this an artificial example or a real-life-scenario example?

@jlesquembre
Copy link
Contributor Author

It is a minimal example, the real world example is that I run maven in a temp dir to see what files are installed and generate a cache. For some reason, some directories are read-only.
In general, it applies to any tool you want to run in a temporary directory, for testing purposes. I could image the same issue if I want to write tests for Nix.

On those cases, you don't have control over the external tool.

But if that case doesn't make sense, or you don't what to support it, feel free to close this issue.

@borkdude
Copy link
Contributor

I'm fine with receiving the PR. Please make the :force option without a question-mark, which is the style adopted for this library.

jlesquembre added a commit to jlesquembre/fs that referenced this issue Dec 19, 2023
jlesquembre added a commit to jlesquembre/fs that referenced this issue Dec 19, 2023
borkdude pushed a commit that referenced this issue Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants