Skip to content

Commit

Permalink
May be finally fix the file copy bug
Browse files Browse the repository at this point in the history
  • Loading branch information
verma committed Jun 20, 2014
1 parent fe357ba commit 4142940
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/dakait/downloader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(ns dakait.downloader
(:use dakait.config
[dakait.util :only (join-path)]
[clojure.core.match :only (match)]
[clojure.core.async :only (thread)]
[clojure.tools.logging :only (info warn error)])
(:require
Expand Down Expand Up @@ -121,16 +122,22 @@
(let [[src dest f] next-task
p (download src dest)]
(info "Process is: " (apply str p))
(reset! active-downloads (conj @active-downloads (conj (vec p) f)))))))
(let [new-dl-state (conj (vec p) f false)] ; false indicates that the user has not been notified about this completion yet
(reset! active-downloads (conj @active-downloads new-dl-state)))))))

(doseq [task @active-downloads]
(let [t (first task)]
(when (realized? t)
(info "Exited code: " @t ", Now triggering callback")
((last task) (= @t 0)))))
(swap! active-downloads
(fn [dls]
(map #(match [%]
[[(t :guard realized?) s d cb false]] (do
(cb (= @t 0))
[t s d cb true])
:else %) dls)))

;; Remove any completed futures from our active downloads list
(reset! active-downloads (remove #(->> % first realized?) @active-downloads))
(swap! active-downloads
(fn [dls]
(remove #(last %) dls)))

(catch Exception e
(warn "Exception in downloader thread: " (.getMessage e))
(.printStackTrace e))
Expand All @@ -140,7 +147,7 @@
(defn downloads-in-progress
"Gets all active downloads"
[]
(map (fn [[fut src dest]]
(map (fn [[fut src dest & rest]]
{:from src
:to dest
:download-status (get @download-states src)}) @active-downloads))
Expand Down
2 changes: 2 additions & 0 deletions src/dakait/staging.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
(info "There is no download state, start one")
(start-download target-path (config :staging-dir)
(fn [code]
(info "File download completed! performing post download stuff")
(info "Process completion code is" code)
(if code ;; this file was successfully downloaded, move the file to destination
(let [info (get @staged target-path)]
(move-to-dir (join-path (config :staging-dir) (filename target-path)) (:dest info))
Expand Down

0 comments on commit 4142940

Please sign in to comment.