Fork me on GitHub
#beginners
<
2023-01-04
>
Ben Lieberman18:01:20

Can someone help me understand this?

(-> "GOOGLE_APPLICATION_CREDENTIALS" ;; envvar
    (System/getenv)
    (java.io.File.)
    .exists) ;; => false

(-> "./tokens/StoredCredential"
 (java.io.File.)
 .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.)

andy.fingerhut18:01:30

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

andy.fingerhut18:01:54

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.

hiredman18:01:26

the jvm doesn't know about ~

👀 2
hiredman18:01:05

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

hiredman18:01:29

~ 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?

hiredman18:01:43

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

hiredman18:01:22

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

hiredman18:01:06

user=> (.getCanonicalPath (java.io.File. "~/foo"))
"/home/kevin/~/foo"
user=>

hiredman18:01:40

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

andy.fingerhut18:01:04

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

andy.fingerhut18:01:25

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: