mirror of
https://github.com/janet-lang/janet
synced 2024-11-25 09:47:17 +00:00
Switch fexists to use os/stat when available.
When os/stat is not available, we first try to read one byte from the file before saying it is good. If that fails, it is not a file that we can read from so it counts as not found.
This commit is contained in:
parent
6c68c7a35f
commit
e5a56174e2
@ -1588,9 +1588,19 @@
|
|||||||
on Windows is C:/Janet/Library."
|
on Windows is C:/Janet/Library."
|
||||||
(or (process/opts "JANET_PATH") ""))
|
(or (process/opts "JANET_PATH") ""))
|
||||||
|
|
||||||
(defn- fexists [path]
|
# Version of fexisst that works even with a reduced OS
|
||||||
(def f (file/open path :r+))
|
(if-let [has-stat (_env 'os/stat)]
|
||||||
(if f (do (file/close f) path)))
|
(let [stat (has-stat :value)]
|
||||||
|
(defglobal "fexists" (fn fexists [path] (= :file (stat path :mode)))))
|
||||||
|
(defglobal "fexists"
|
||||||
|
(fn fexists [path]
|
||||||
|
(def f (file/open path))
|
||||||
|
(when f
|
||||||
|
(def res
|
||||||
|
(try (do (file/read f 1) true)
|
||||||
|
([err] nil)))
|
||||||
|
(file/close f)
|
||||||
|
res))))
|
||||||
|
|
||||||
(defn module/find
|
(defn module/find
|
||||||
"Try to match a module or path name from the patterns in module/paths.
|
"Try to match a module or path name from the patterns in module/paths.
|
||||||
|
Loading…
Reference in New Issue
Block a user