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

java.io.File.canWrite() is not sufficient to test whether ".cpcache" dir can be created #120

Closed
jdjohnston opened this issue Dec 20, 2023 · 13 comments

Comments

@jdjohnston
Copy link

This is an issue on Windows 7. Can't say if it's true for newer Windows or other OSes.

I was looking for a test case to try verify that I was actually using 1.11.1.1429 by setting DEPS_CLJ_TOOLS_VERSION as you suggested. One new item is the handling of .cpcache if the cwd isn't writable. deps.clj uses java.io.File.canWrite(), but that doesn't always work, which is easy to demonstrate in bb.

I set C:\Users\JDJ\tmp\xper such that I didn't have write or dir creation privileges in xper. I wasn't surprised that 1.11.1.1413 had problems, but 1.11.1.1429 was supposed to handle that case. However, I got the same error. After inspecting the Clojure code, I tried the following in bb:

C:\Users\JDJ\tmp\xper
λ bb
Babashka v1.3.186 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (-> (io/file ".") (.canWrite))
true
user=> (fs/create-dir ".cpache")
java.nio.file.AccessDeniedException: .cpache [at :2:1]
user=>

Please ignore the typo (".cpache"). :)

@borkdude
Copy link
Owner

I'm open to a PR which fixes this. Bonus points for a test.

@jdjohnston
Copy link
Author

Not sure when I'd have a chance to write up a PR. Test in Linux is, of course, easy: mkdir DIR; chmod 0555 DIR. Windows: shrug

As for code, I think you already have it: babashka.fs/writable? Without using babashka.fs directly here's another bb snippet [*]:

user=> (import 'java.nio.file.Files)
java.nio.file.Files
user=> (-> "." io/file (.toPath) Files/isWritable)
false

Not sure if there are any corner cases, but this works for R/O dirs in both Windows 7 & Linux, doing some quick tests.

[*] Thanks so much for bb. It makes experimenting in the Clojureverse not only easy, but downright fun!

@borkdude
Copy link
Owner

So there is a difference between canWrite and isWriteable, that is the crux?

@jdjohnston
Copy link
Author

jdjohnston commented Dec 21, 2023 via email

@jlesquembre
Copy link

@jdjohnston Can you provide an example where canWrite and isWriteable return a different value? I can't reproduce it.

@jdjohnston
Copy link
Author

jdjohnston commented Dec 21, 2023 via email

@jdjohnston
Copy link
Author

jdjohnston commented Dec 21, 2023 via email

@borkdude
Copy link
Owner

Is the summary that we should switch to java.nio isWritable and then we can close the issue? Happy to do this.

@jdjohnston
Copy link
Author

jdjohnston commented Dec 21, 2023 via email

@borkdude
Copy link
Owner

ok, pushed. you can perhaps test the Windows build artifact when CI finishes. I can make a new release tomorrow or so if that's necessary

@jdjohnston
Copy link
Author

jdjohnston commented Dec 22, 2023 via email

@borkdude
Copy link
Owner

borkdude commented Jan 9, 2024

New release is available

@jdjohnston
Copy link
Author

@borkdude The new release recognizes that the test dir is R/O, as desired. No obvious regression :)

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

No branches or pull requests

3 participants