Skip to content

Commit 7340212

Browse files
committed
Correctly clear the cache on windows.
Git marks some files as "readonly" on windows preventing deletion via naive means. Use the "attrib" utility to take care of that.
1 parent 2e90623 commit 7340212

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

bin/janet-pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
(defn clear-cache
186186
[]
187187
(def cache (path/join (dyn *syspath*) ".cache"))
188-
(sh/rm cache))
188+
(sh/rm-readonly cache))
189189

190190
(defn list-pkgs
191191
[&opt search]

spork/pm.janet

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,6 @@
721721
(spit (path/join path "bin" "activate.bat") (enter-cmd-template opts))
722722
(spit (path/join path "bin" "deactivate.bat") (exit-cmd-template opts))
723723
(print "created project shell environment at " path)
724-
(if (or (= :windows (os/which)) (= :mingw (os/which)))
725-
(print "run `" path "\\bin\\activate` to enter the new environment, then `deactivate` to exit.")
726-
(print "run `. " path "/bin/activate` to enter the new environment, then `deactivate` to exit.")))
724+
(print "(PowerShell) run `. " path "/bin/activate.ps1` to enter the new environment, then `deactivate` to exit.")
725+
(print "(CMD) run `" path "\\bin\\activate` to enter the new environment, then `deactivate` to exit.")
726+
(print "(Unix sh) run `. " path "/bin/activate` to enter the new environment, then `deactivate` to exit."))

spork/sh.janet

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@
6868
# Default, try to remove
6969
(os/rm path)))
7070

71+
(defn rm-readonly
72+
"Like sh/rm, but will also remove readonly files and folders on windows"
73+
[path]
74+
(def os (os/which))
75+
(when (or (= os :windows) (= os :mingw))
76+
(def root
77+
(if (= :file (os/stat path :mode))
78+
path
79+
(path/join path "*.*")))
80+
(exec "attrib" "-R" "-H" root "/S" "/D"))
81+
(rm path))
82+
7183
(defn exists?
7284
"Check if the given file or directory exists. (Follows symlinks)"
7385
[path]

0 commit comments

Comments
 (0)