 (defn new-hash [url]
   (copy (reader (hash-url url)) (hash-location url)))
 
-(defn download-index [id url]
+(defn published? [url]
+  (try
+    (= HttpURLConnection/HTTP_OK
+       (.getResponseCode
+        (doto (.openConnection (hash-url url))
+          (.setRequestMethod "HEAD"))))
+    (catch Exception _ false)))
+
+(defn download-index [url]
+  (sherlock/update-index url)
+  (new-hash url))
+
+(defn init-index [id url]
   (when (sherlock/download-needed? url)
     (log (str "Downloading index for " id ". This might take a bit."))
-    (sherlock/update-index url)
-    (new-hash url)))
+    (download-index url)))
 
-
-(defn needs-updating? [id url]
-  (when (and (not= (slurp (hash-location url))
-                   (slurp (hash-url url))))
-    (println (format "The index for %s is out of date. Pass --update to update it." id))))
+(defn update-message [id url]
+  (let [hash-location (hash-location url)]
+    (when (and (.exists hash-location)
+               (not= (slurp hash-location)
+                     (slurp (hash-url url))))
+      (println (format "The index for %s is out of date. Pass --update to update it." id)))))
 
 (defn update-repo [id url]
   (log (str "Updating index for " id ". This might take a bit."))
-  (sherlock/update-index url)
-  (new-hash url))
+  (download-index url))
 
 (defn identifier [{:keys [group-id artifact-id]}]
   (if group-id

  {[page] :page repos :repos search :search update :update}
  (let [page (if page (Integer. page) 1)]
    (binding [sherlock/*page-size* 10]
      (doseq [[id url] (select-repos repos)]
        (download-index id url)
        (when update (update-repo id url))
        (needs-updating? id url)
        (print-results
         id page
         (sherlock/get-page page (sherlock/search url (join " " search) page)))))))

        cake.core
        [bake.core :only [log]]
        [clojure.string :only [join]]
        [clojure.java.io :only [as-url file copy reader]])
  (:require [sherlock.core :as sherlock])
  (:import java.net.HttpURLConnection))

(defn select-repos [repos]
  (let [repositories (:repositories *project*)]
