Skip to content

Commit

Permalink
Don't share tmp repos between artifacts [#541]
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
tobias committed Jun 27, 2016
1 parent e0a1fd5 commit 1378f6a
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/clojars/routes/repo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -77,8 +88,6 @@
(= match name)
(re-find match name))))

(def metadata-edn "_metadata.edn")

(defn find-artifacts
([dir]
(find-artifacts dir true))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -263,6 +272,7 @@
(upload-request
db
groupname
artifact
session
(fn [_ upload-dir]
(spit (io/file upload-dir metadata-edn)
Expand Down Expand Up @@ -296,6 +306,7 @@
(upload-request
db
groupname
artifact
session
(fn [account upload-dir]
(let [file (io/file upload-dir group artifact file)]
Expand Down

0 comments on commit 1378f6a

Please sign in to comment.