Skip to content

Commit

Permalink
Create tmpfile with mode 0600
Browse files Browse the repository at this point in the history
  • Loading branch information
micha committed Aug 28, 2016
1 parent 17855d2 commit f339a8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Format paths in `boot.class.path` and `fake.class.path` system properties
with correct, platform-specific paths [#488][488].
- Eliminate runtime reflection in `boot.core/deftask` macro [#490][490].
- Create bootscript tmpfile with mode `0600` instead of `0664`.

#### Tasks

Expand Down
17 changes: 12 additions & 5 deletions boot/pod/src/boot/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
(:import
[java.net URI]
[java.io File]
[java.nio.file.attribute FileAttribute]
[java.lang.management ManagementFactory]
[java.nio.file Files StandardCopyOption FileVisitOption]
[java.lang.management ManagementFactory])
[java.nio.file.attribute FileAttribute PosixFilePermissions])
(:refer-clojure :exclude [sync name file-seq]))

(set! *warn-on-reflection* true)
Expand All @@ -21,6 +21,11 @@
(def ^:dynamic *sync-delete* true)
(def ^:dynamic *hard-link* true)

(def tmpfile-permissions
(into-array FileAttribute
[(PosixFilePermissions/asFileAttribute
(PosixFilePermissions/fromString "rw-------"))]))

(defn file? [f] (when (try (.isFile (io/file f)) (catch Throwable _)) f))
(defn dir? [f] (when (try (.isDirectory (io/file f)) (catch Throwable _)) f))
(defn exists? [f] (when (try (.exists (io/file f)) (catch Throwable _)) f))
Expand Down Expand Up @@ -128,9 +133,11 @@

(defn ^File tmpfile
([prefix postfix]
(doto (java.io.File/createTempFile prefix postfix) .deleteOnExit))
([prefix postfix dir]
(doto (java.io.File/createTempFile prefix postfix dir) .deleteOnExit)))
(let [path (Files/createTempFile prefix postfix tmpfile-permissions)]
(doto (.toFile path) (.deleteOnExit))))
([prefix postfix ^File dir]
(let [path (Files/createTempFile (.toPath dir) prefix postfix tmpfile-permissions)]
(doto (.toFile path) (.deleteOnExit)))))

(defn ^File tmpdir
([prefix]
Expand Down

0 comments on commit f339a8d

Please sign in to comment.