diff --git a/backend/src/app/rpc/management/exporter.clj b/backend/src/app/rpc/management/exporter.clj index da1bb6a94c..20e791e7d0 100644 --- a/backend/src/app/rpc/management/exporter.clj +++ b/backend/src/app/rpc/management/exporter.clj @@ -37,7 +37,7 @@ data (-> (sto/content (:path content)) (sto/wrap-with-hash hash)) content {::sto/content data - ::sto/deduplicate? true + ::sto/deduplicate? false ::sto/touched-at (ct/in-future {:minutes 10}) :profile-id profile-id :content-type (:mtype content) diff --git a/backend/src/app/storage.clj b/backend/src/app/storage.clj index ce7a063148..f30d8762ec 100644 --- a/backend/src/app/storage.clj +++ b/backend/src/app/storage.clj @@ -135,7 +135,8 @@ ;; still not deleted. result (when (and (::deduplicate? params) (:hash mdata) - (:bucket mdata)) + (:bucket mdata) + (not= "tempfile" (:bucket mdata))) (let [result (get-database-object-by-hash connectable backend (:bucket mdata) (:hash mdata))] diff --git a/backend/test/backend_tests/rpc_management_test.clj b/backend/test/backend_tests/rpc_management_test.clj index 5937d547e5..601e8b3d35 100644 --- a/backend/test/backend_tests/rpc_management_test.clj +++ b/backend/test/backend_tests/rpc_management_test.clj @@ -19,7 +19,8 @@ [backend-tests.storage-test :refer [configure-storage-backend]] [buddy.core.bytes :as b] [clojure.test :as t] - [datoteka.fs :as fs])) + [datoteka.fs :as fs] + [datoteka.io :as io])) (t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) @@ -39,6 +40,23 @@ (t/is (nil? (:error out))) (:result out))) +(t/deftest upload-tempfile-returns-fresh-object-for-same-content + (let [profile (th/create-profile* 1 {:is-active true}) + path (fs/create-tempfile :dir "/tmp/penpot" :prefix "test-upload-tempfile-") + _ (io/write* path "content") + params {::th/type :upload-tempfile + ::rpc/profile-id (:id profile) + :content {:filename "export.png" + :path path + :mtype "image/png" + :size 7}} + out1 (th/management-command! params) + out2 (th/management-command! params)] + (t/is (nil? (:error out1))) + (t/is (nil? (:error out2))) + (t/is (not= (get-in out1 [:result :id]) + (get-in out2 [:result :id]))))) + (t/deftest duplicate-file (let [storage (-> (:app.storage/storage th/*system*) (configure-storage-backend)) diff --git a/backend/test/backend_tests/storage_test.clj b/backend/test/backend_tests/storage_test.clj index cff47dec51..348a978fc2 100644 --- a/backend/test/backend_tests/storage_test.clj +++ b/backend/test/backend_tests/storage_test.clj @@ -48,6 +48,23 @@ (t/is (= "content" (slurp (sto/get-object-data storage object)))) (t/is (= "content" (slurp (sto/get-object-path storage object)))))) +(t/deftest tempfile-objects-are-not-deduplicated + (let [storage (-> (:app.storage/storage th/*system*) + (configure-storage-backend)) + content (-> (sto/content "content") + (sto/wrap-with-hash "same-hash")) + object1 (sto/put-object! storage {::sto/content content + ::sto/deduplicate? true + ::sto/touched-at (ct/in-future {:minutes 10}) + :bucket "tempfile" + :content-type "text/plain"}) + object2 (sto/put-object! storage {::sto/content content + ::sto/deduplicate? true + ::sto/touched-at (ct/in-future {:minutes 10}) + :bucket "tempfile" + :content-type "text/plain"})] + (t/is (not= (:id object1) (:id object2))))) + (t/deftest put-and-retrieve-expired-object (let [storage (-> (:app.storage/storage th/*system*) (configure-storage-backend))