Fork me on GitHub
#babashka
<
2023-09-02
>
Darrell00:09:29

I’m having a weird problem with babashka.fs. If I run this code in the REPL it works without error:

(let [host ""
        user "********"
        pass "********"]
    (fs/unzip (fs/file "/tmp" "CATALOG.zip") (fs/file "/tmp") {:replace-existing true}))
However, if I build an uberjar and run that, I get this error:
Exception in thread "main" java.nio.file.FileAlreadyExistsException: /tmp
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:94)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:398)
	at java.base/java.nio.file.Files.createDirectory(Files.java:700)
	at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:807)
	at java.base/java.nio.file.Files.createDirectories(Files.java:753)
	at babashka.fs$create_dirs.invokeStatic(fs.cljc:421)
	at babashka.fs$create_dirs.invoke(fs.cljc:416)
	at babashka.fs$create_dirs.invokeStatic(fs.cljc:419)
	at babashka.fs$create_dirs.invoke(fs.cljc:416)
	at babashka.fs$unzip.invokeStatic(fs.cljc:935)
	at babashka.fs$unzip.invoke(fs.cljc:925)
	at scw.full_catalog_import$download_and_unzip.invokeStatic(full_catalog_import.clj:350)
	at scw.full_catalog_import$download_and_unzip.invoke(full_catalog_import.clj:334)
	at scw.full_catalog_import$_main.invokeStatic(full_catalog_import.clj:358)
	at scw.full_catalog_import$_main.invoke(full_catalog_import.clj:356)
	at clojure.lang.AFn.applyToHelper(AFn.java:152)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at scw.full_catalog_import.main(Unknown Source)
Any idea what might be causing that?

2
Bob B01:09:52

according to the docs of createDirectories, that exception may be thrown if the file exists and is not a directory (/tmp in this case)

Darrell03:09:21

That’s what’s so strange. /tmp is a valid directory and, I don’t get that error when I run that code in the REPL.

Darrell03:09:51

It seems to me as if it’s trying to create “/tmp” instead of unzipping the file into that directory. Could that be the problem?

Bob B03:09:34

it's trying to create the directory before extracting to it

Darrell03:09:53

Ah, ok. So if I use (fs/file "/tmp/DATA"), for example, it seems to work as expected.

Bob B03:09:57

I don't know the full mechanics of how the uberjar runs, but maybe it does something with a file called 'tmp' or something - could explain the difference in running from the repl vs an uberjar - how about if you run it via bb -f, but not as an uberjar

borkdude08:09:46

Hmz, the bug comes from:

user=> (fs/create-dirs "/tmp")
Execution error (FileAlreadyExistsException) at sun.nio.fs.UnixException/translateToIOException (UnixException.java:94).
But I think this has to do with /tmp being a symlink...

borkdude08:09:25

As create-dirs just defers to Files/createDirectories I would argue this is standard JVM behavior

Darrell15:09:27

That makes sense, @U04V15CAJ since /tmp on macOS is a symlink to /private/tmp.

Darrell15:09:44

Thanks for the help @U013JFLRFS8 and @U04V15CAJ!

true.neutral23:09:14

Hey. I'm having trouble marrying babashka with Cursive: I've created an empty deps project, with a single script requiring babashka.curl , marked it as babashka script, but nevertheless Intellij won't recognize babashka.curl , i.e. cannot resolve it and give any meaningful help with it. Could someone help?

true.neutral00:09:12

Actually it won't resolve almost anything, ns , defn , etc. 0.o

cfleming00:09:11

I’m travelling at the moment, but check the first item here and see if that helps: https://cursive-ide.com/userguide/troubleshooting.html#help-lots-of-symbols-don-t-resolve edit: fixed link now I’m on desktop

Bob B01:09:19

just taking a wild stab in the dark - what version of babashka are you using?

borkdude10:09:13

@U5USC6WNL did you create a bb.edn file?

borkdude10:09:21

this might be necessary for cursive, not sure

true.neutral21:09:10

Thank you for the replies! From the top, the macro doesn't really help, as it's just everything that doesn't resolve. The bb version is 1.3.184 And the bb.edn file, nope. I made it work somehow but honestly, I don't know what helped, as I tried creating bb.edn , specifying source paths, then deleting it again, changing SDK, removing and adding babashka support to the module, etc. It worked at some point: it's not bb.edn , as I deleted it and it still works. The only thing I can tell is: in Project View, the babashka dependency is shown correctly (as a tree node that can be expanded into separate jars); before that, it was more of an unexpandable label. BTW, just to make sure it's my project setup, not something else, I downloaded neil and tried to open it with Cursive, and it worked correctly from the get go.

true.neutral21:09:40

So I guess at some point IntelliJ IDEA's state somehow got messed up (which is strange as it's literally an empty project I just created), but still. Eh.

true.neutral21:09:15

On that note, maybe nuking .iml file and reopening the project could help.