babashka / bbin

Install any Babashka script or project with one command
MIT License
139 stars 9 forks source link

`bin-dir` is not resolved correctly on Windows platform #19

Closed littleli closed 2 years ago

littleli commented 2 years ago

This is from Windows Terminal + Powershell:

~ $ bbin install io.github.rads/watch
----- Error --------------------------------------------------------------------
Type:     java.nio.file.AccessDeniedException
Message:  C:\Users\.bbin
Location: C:\Users\alesn\scoop\apps\bbin\current\bbin:61:3

----- Context ------------------------------------------------------------------
57:          (when-let [v (:local/root cli-opts)]
58:            {:local/root (str (fs/canonicalize v {:nofollow-links true}))})))
59:
60: (defn ensure-bbin-dirs [cli-opts]
61:   (fs/create-dirs (bin-dir cli-opts)))
      ^--- C:\Users\.bbin
62:
63: (ns babashka.bbin.scripts
64:   (:require [babashka.fs :as fs]
65:             [babashka.deps :as deps]
66:             [rads.deps-info.infer :as deps-info-infer]

----- Stack trace --------------------------------------------------------------
babashka.fs/create-dirs             - <built-in>
babashka.bbin.util/ensure-bbin-dirs - C:\Users\alesn\scoop\apps\bbin\current\bbin:61:3
babashka.bbin.util/ensure-bbin-dirs - C:\Users\alesn\scoop\apps\bbin\current\bbin:60:1
babashka.bbin.scripts               - C:\Users\alesn\scoop\apps\bbin\current\bbin:337:7
babashka.bbin.cli                   - C:\Users\alesn\scoop\apps\bbin\current\bbin:373:10
babashka.bbin.cli/bbin              - C:\Users\alesn\scoop\apps\bbin\current\bbin:403:5
babashka.bbin.cli/bbin              - C:\Users\alesn\scoop\apps\bbin\current\bbin:400:1
babashka.bbin.cli                   - C:\Users\alesn\scoop\apps\bbin\current\bbin:406:3
clojure.core/apply                  - <built-in>
babashka.bbin.cli                   - C:\Users\alesn\scoop\apps\bbin\current\bbin:409:3

Error reported on https://github.com/babashka/bbin/blob/main/bbin#L61

But in fact the issue seems to be here https://github.com/babashka/bbin/blob/main/bbin#L47

Looks like (fs/expand-home) is not working correctly and it forgets last component from the path. I'll do a bug report to babashka/fs too.

My recommendation is to get user directory from environment variables which are mutually exclusive on each platform, something along these lines:

(def ^:dynamic *bbin-root*
  (str (or (.get (System/getenv) "HOME")
           (.get (System/getenv) "USERPROFILE"))
  File/separator
  ".bbin"))

Probably just wait a moment to fs/expand-home to be fixed.

littleli commented 2 years ago

After short conversation with @borkdude it turned out fs/expend-home will be fixed with the very next release of bb

rads commented 2 years ago

Thanks for creating this issue. I bumped the minimum Babashka version to 0.9.162 and made sure we check this even in the generated bbin script.