                                            (not (.exists (io/file dir "maven-metadata.xml"))))]
                              dir)
               versions (set (map (memfn getName) version-dirs))
-              missing-versions? (not= versions (set (.getVersions (.getVersioning metadata))))
+              missing-versions? (not= versions (set (.getVersions (get-versioning metadata))))
               invalid-sums? (not (futil/valid-sums? f))]
         :when (or missing-versions? invalid-sums?)]
     {:file              f

                  [file (futil/sum-file file :sha1) (futil/sum-file file :md5)]))))

(defn repair-versions [{:keys [file metadata version-dirs]}]
  (let [versioning (.getVersioning metadata)
        sorted-dirs (sort-by #(.lastModified %) version-dirs)]
    ;; remove existing versions, then write dir versions in dir creation order
    (run! #(.removeVersion versioning %) (into [] (.getVersions versioning)))
    (run! #(.addVersion versioning %) (map (memfn getName) sorted-dirs))
    ;; set release to latest !snapshot
    (.setRelease versioning
                 (->> sorted-dirs
                      (filter #(not (.endsWith (.getName %) "SNAPSHOT")))
                      last
                      .getName))
    ;; set lastUpdated to latest version
    (.setLastUpdated versioning (.format date-formatter
                                         (-> sorted-dirs last .lastModified Date.)))

    (println "Usage: repo-path backup-path (:repair|:report)")
    (let [[repo backup-dir action] args]
      (doseq [md (find-bad-metadata repo)]
        (prn (-> md
                 (dissoc :version-dirs :metadata)
                 (update :file (memfn getAbsolutePath))))
        (when (= ":repair" action)
          (repair-metadata (io/file backup-dir) md))))))
