From 1378f6a8a0e0572bf1abef740a55e67c9eaad828 Mon Sep 17 00:00:00 2001 From: Toby Crawley Date: Mon, 27 Jun 2016 13:41:53 -0400 Subject: [PATCH] Don't share tmp repos between artifacts [#541] lein-module based projects will share an aether session when deploying, but we want each module to have it's own session, so they will each have their own atomic deploy. Without this change, the second and all subsequent module deploys will fail. The fix here is to store the tmp repos as a seq, and find the existing one that matches the current upload, or creating a new one if none match. This would allow interleaving files for different artifacts in the same session, which none of the existing tooling does, but who knows what craziness exists out there? --- src/clojars/routes/repo.clj | 41 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/clojars/routes/repo.clj b/src/clojars/routes/repo.clj index b1dde2bf..33027f65 100644 --- a/src/clojars/routes/repo.clj +++ b/src/clojars/routes/repo.clj @@ -45,24 +45,35 @@ (let [filename (if (string? file) file (.getName file))] (.endsWith filename ".pom"))) -(defn find-upload-dir [{:keys [upload-dir]}] - (let [dir (io/file upload-dir)] - (if (and dir (.exists dir)) - dir - (let [dir' (io/file (FileUtils/getTempDirectory) - (str "upload-" (UUID/randomUUID)))] - (FileUtils/forceMkdir dir') - dir')))) - -(defn upload-request [db groupname session f] +(def metadata-edn "_metadata.edn") + +(defn read-metadata [dir] + (let [md-file (io/file dir metadata-edn)] + (when (.exists md-file) + (read-string (slurp md-file))))) + +(defn find-upload-dir [group artifact {:keys [upload-dirs]}] + (if-let [dir (some (fn [dir] + (let [dir (io/file dir)] + (when (and dir (.exists dir) + (= [group artifact] ((juxt :group :name) (read-metadata dir)))) + dir))) + upload-dirs)] + dir + (doto (io/file (FileUtils/getTempDirectory) + (str "upload-" (UUID/randomUUID))) + (FileUtils/forceMkdir)))) + +(defn upload-request [db groupname artifact session f] (with-account (fn [account] - (let [upload-dir (find-upload-dir session)] + (let [upload-dir (find-upload-dir groupname artifact session)] (require-authorization db account groupname (partial f account upload-dir)) ;; should we only do 201 if the file didn't already exist? {:status 201 :headers {} - :session (assoc session :upload-dir (.getAbsolutePath upload-dir)) + :session (update session + :upload-dirs #((fnil conj []) % (.getAbsolutePath upload-dir))) :body nil})))) (defn find-pom [dir] @@ -77,8 +88,6 @@ (= match name) (re-find match name)))) -(def metadata-edn "_metadata.edn") - (defn find-artifacts ([dir] (find-artifacts dir true)) @@ -219,7 +228,7 @@ (throw-invalid (str "invalid pom file: " (.getMessage e)) {:file pom-file} e))) - {:keys [group group-path name] :as posted-metadata} (read-string (slurp (io/file dir metadata-edn)))] + {:keys [group group-path name] :as posted-metadata} (read-metadata dir)] ;; since we trigger on maven-metadata.xml, we don't actually ;; have the sums for it because they are uploaded *after* the @@ -263,6 +272,7 @@ (upload-request db groupname + artifact session (fn [_ upload-dir] (spit (io/file upload-dir metadata-edn) @@ -296,6 +306,7 @@ (upload-request db groupname + artifact session (fn [account upload-dir] (let [file (io/file upload-dir group artifact file)]