mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 21:56:38 +02:00
✨ Use a prefixed dir for storing temp files
And mark them for deletion on JVM exit.
This commit is contained in:
parent
9649878fd8
commit
a31be7e2ff
14 changed files with 32 additions and 27 deletions
|
@ -44,7 +44,7 @@
|
||||||
[clojure.walk :refer [macroexpand-all]]
|
[clojure.walk :refer [macroexpand-all]]
|
||||||
[criterium.core :as crit]
|
[criterium.core :as crit]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.core]
|
[datoteka.fs :as fs]
|
||||||
[integrant.core :as ig]
|
[integrant.core :as ig]
|
||||||
[malli.core :as m]
|
[malli.core :as m]
|
||||||
[malli.dev.pretty :as mdp]
|
[malli.dev.pretty :as mdp]
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
[promesa.exec :as px]
|
[promesa.exec :as px]
|
||||||
[promesa.exec.csp :as sp]))
|
[promesa.exec.csp :as sp]))
|
||||||
|
|
||||||
|
(def default-tmp-dir "/tmp/penpot")
|
||||||
|
|
||||||
(declare ^:private remove-temp-file)
|
(declare ^:private remove-temp-file)
|
||||||
(declare ^:private io-loop)
|
(declare ^:private io-loop)
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
|
|
||||||
(defmethod ig/init-key ::cleaner
|
(defmethod ig/init-key ::cleaner
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
|
(fs/create-dir default-tmp-dir)
|
||||||
(px/fn->thread (partial io-loop cfg)
|
(px/fn->thread (partial io-loop cfg)
|
||||||
{:name "penpot/storage/tmp-cleaner" :virtual true}))
|
{:name "penpot/storage/tmp-cleaner" :virtual true}))
|
||||||
|
|
||||||
|
@ -70,18 +73,14 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn tempfile
|
(defn tempfile
|
||||||
"Returns a tmpfile candidate (without creating it)"
|
|
||||||
[& {:keys [suffix prefix min-age]
|
[& {:keys [suffix prefix min-age]
|
||||||
:or {prefix "penpot."
|
:or {prefix "penpot."
|
||||||
suffix ".tmp"}}]
|
suffix ".tmp"}}]
|
||||||
(let [path (fs/tempfile :suffix suffix :prefix prefix)]
|
(let [path (fs/create-tempfile
|
||||||
(sp/offer! queue [path (some-> min-age dt/duration)])
|
:perms "rw-r--r--"
|
||||||
path))
|
:dir default-tmp-dir
|
||||||
|
:suffix suffix
|
||||||
(defn create-tempfile
|
:prefix prefix)]
|
||||||
[& {:keys [suffix prefix min-age]
|
(fs/delete-on-exit! path)
|
||||||
:or {prefix "penpot."
|
|
||||||
suffix ".tmp"}}]
|
|
||||||
(let [path (fs/create-tempfile :suffix suffix :prefix prefix)]
|
|
||||||
(sp/offer! queue [path (some-> min-age dt/duration)])
|
(sp/offer! queue [path (some-> min-age dt/duration)])
|
||||||
path))
|
path))
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[environ.core :refer [env]]
|
[environ.core :refer [env]]
|
||||||
[expound.alpha :as expound]
|
[expound.alpha :as expound]
|
||||||
[integrant.core :as ig]
|
[integrant.core :as ig]
|
||||||
|
@ -127,6 +127,8 @@
|
||||||
app.auth/verify-password (fn [a b] {:valid (= a b)})
|
app.auth/verify-password (fn [a b] {:valid (= a b)})
|
||||||
app.common.features/get-enabled-features (fn [& _] app.common.features/supported-features)]
|
app.common.features/get-enabled-features (fn [& _] app.common.features/supported-features)]
|
||||||
|
|
||||||
|
(fs/create-dir "/tmp/penpot")
|
||||||
|
|
||||||
(let [templates [{:id "test"
|
(let [templates [{:id "test"
|
||||||
:name "test"
|
:name "test"
|
||||||
:file-uri "test"
|
:file-uri "test"
|
||||||
|
@ -191,6 +193,7 @@
|
||||||
(let [path (fs/path "/tmp/penpot")]
|
(let [path (fs/path "/tmp/penpot")]
|
||||||
(when (fs/exists? path)
|
(when (fs/exists? path)
|
||||||
(fs/delete (fs/path "/tmp/penpot")))
|
(fs/delete (fs/path "/tmp/penpot")))
|
||||||
|
(fs/create-dir "/tmp/penpot")
|
||||||
(next)))
|
(next)))
|
||||||
|
|
||||||
(defn serial
|
(defn serial
|
||||||
|
@ -496,7 +499,7 @@
|
||||||
(defn tempfile
|
(defn tempfile
|
||||||
[source]
|
[source]
|
||||||
(let [rsc (io/resource source)
|
(let [rsc (io/resource source)
|
||||||
tmp (fs/create-tempfile)]
|
tmp (fs/create-tempfile :dir "/tmp/penpot" :prefix "test-")]
|
||||||
(io/copy (io/file rsc)
|
(io/copy (io/file rsc)
|
||||||
(io/file tmp))
|
(io/file tmp))
|
||||||
tmp))
|
tmp))
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[mockery.core :refer [with-mocks]]))
|
[mockery.core :refer [with-mocks]]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]))
|
[datoteka.fs :as fs]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
(t/use-fixtures :each th/database-reset)
|
(t/use-fixtures :each th/database-reset)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[mockery.core :refer [with-mocks]]))
|
[mockery.core :refer [with-mocks]]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
[backend-tests.storage-test :refer [configure-storage-backend]]
|
[backend-tests.storage-test :refer [configure-storage-backend]]
|
||||||
[buddy.core.bytes :as b]
|
[buddy.core.bytes :as b]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]))
|
[datoteka.fs :as fs]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
(t/use-fixtures :each th/database-reset)
|
(t/use-fixtures :each th/database-reset)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
[app.storage :as sto]
|
[app.storage :as sto]
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]))
|
[datoteka.fs :as fs]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
(t/use-fixtures :each th/database-reset)
|
(t/use-fixtures :each th/database-reset)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[mockery.core :refer [with-mocks]]))
|
[mockery.core :refer [with-mocks]]))
|
||||||
|
|
||||||
;; TODO: profile deletion with teams
|
;; TODO: profile deletion with teams
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
[app.rpc.quotes :as-alias quotes]
|
[app.rpc.quotes :as-alias quotes]
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[mockery.core :refer [with-mocks]]))
|
[mockery.core :refer [with-mocks]]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[mockery.core :refer [with-mocks]]))
|
[mockery.core :refer [with-mocks]]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[datoteka.core :as fs]))
|
[datoteka.fs :as fs]))
|
||||||
|
|
||||||
(t/use-fixtures :once th/state-init)
|
(t/use-fixtures :once th/state-init)
|
||||||
(t/use-fixtures :each th/database-reset)
|
(t/use-fixtures :each th/database-reset)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
[backend-tests.helpers :as th]
|
[backend-tests.helpers :as th]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.core :as fs]
|
[datoteka.fs :as fs]
|
||||||
[datoteka.io :as io]
|
[datoteka.io :as io]
|
||||||
[mockery.core :refer [with-mocks]]))
|
[mockery.core :refer [with-mocks]]))
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,14 @@
|
||||||
|
|
||||||
funcool/tubax {:mvn/version "2021.05.20-0"}
|
funcool/tubax {:mvn/version "2021.05.20-0"}
|
||||||
funcool/cuerdas {:mvn/version "2023.11.09-407"}
|
funcool/cuerdas {:mvn/version "2023.11.09-407"}
|
||||||
funcool/promesa {:git/sha "0c5ed6ad033515a2df4b55addea044f60e9653d0"
|
funcool/promesa
|
||||||
:git/url "https://github.com/funcool/promesa"}
|
{:git/sha "0c5ed6ad033515a2df4b55addea044f60e9653d0"
|
||||||
|
:git/url "https://github.com/funcool/promesa"}
|
||||||
|
|
||||||
funcool/datoteka {:mvn/version "3.0.66"
|
funcool/datoteka
|
||||||
:exclusions [funcool/promesa]}
|
{:git/sha "5ac3781"
|
||||||
|
:git/tag "3.0.0"
|
||||||
|
:git/url "https://github.com/funcool/datoteka"}
|
||||||
|
|
||||||
lambdaisland/uri {:mvn/version "1.16.134"
|
lambdaisland/uri {:mvn/version "1.16.134"
|
||||||
:exclusions [org.clojure/data.json]}
|
:exclusions [org.clojure/data.json]}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue