Fork me on GitHub
Ben Lieberman18:01:20

Can someone help me understand this?

    .exists) ;; => false

(-> "./tokens/StoredCredential"
 .exists) ;; => true
I am not aware of how/why the existence of a file would be conditional upon the directory I'm in. (The envvar in the first snippet is set to the absolute path of the file in the second.)


What is the value of (-> "GOOGLE_APPLICATION_CREDENTIALS" (System/getenv)) out of curiosity?


And a wild guess: could there be directories in the full path that you do not have read/search permissions for?

Ben Lieberman18:01:32

@U0CMVHBL2 "~/Documents/clojure/writing-workflow/tokens/StoredCredential" and re: permissions, that seems unlikely to me, this is my personal machine and I'm the root user. But then again I wouldn't bet money on it.


the jvm doesn't know about ~

👀 2

you can make the two file objects and compare getCanonicalPath on them


~ is a shell thing, not a feature of the underlying filesystem, the shell often expands it away, and some non-shell code also supports it, but the jvm does not

Ben Lieberman18:01:20

Good to know about ~ here. I used .getCanonicalPath on the file object I created from the envvar and I got back the absolute path of the file appended to the path of my working directory. Is that to be expected?


because it doesn't start with '/' the jvm assumes it is a relative path


calling getCanonicalPath makes it absolute, by prepending the current working directory


user=> (.getCanonicalPath ( "~/foo"))


The file object represents a file named "foo" in a directory named "~" under "/home/kevin"


Seems best to change the value of the env var to not use ~ if you want fewer headaches.


Either that, or write special code for interpreting ~ in the value of any env vars that you want to support it, yourself, explicitly.

Ben Lieberman18:01:20

Yeah, I did already. I put it in my .bashrc as an absolute path and it works now. Thanks @U0NCTKEV8 @U0CMVHBL2 🙏:skin-tone-2: