 (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

      (println (str "[" (identifier artifact) " \"" version "\"]") description))
    (prn)))

(deftask search
  "Search maven repos for artifacts."
  "Search takes a query that is treated as a lucene search query,

      repositories)))

(defn hash-url [url]
  (as-url (str (sherlock/remote-index-url url) ".md5")))

(defn hash-location [url]
  (file (str (sherlock/index-location url) ".md5")))
