summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--downloader.lua22
1 files changed, 15 insertions, 7 deletions
diff --git a/downloader.lua b/downloader.lua
index 768d726..a8519dd 100644
--- a/downloader.lua
+++ b/downloader.lua
@@ -29,16 +29,24 @@ function mt:exec(url, file, cb)
args = cmd,
playback_only = false,
}, function(success, res)
- self.running = false
- self:exec_next()
- if success and res.status == 0 then
- os.rename(tmp, file)
- if cb then
- cb(url, file)
- end
+ success = success and res.status == 0
+ if success then
+ success = os.rename(tmp, file)
else
os.remove(tmp)
end
+
+ -- execute next download after renaming the file but before
+ -- executing the callback function. this avoids duplicate
+ -- downloads when the same file is requested twice in a row,
+ -- without unnecessarily waiting for the callback to complete
+ -- before starting the next download.
+ self.running = false
+ self:exec_next()
+
+ if success and cb then
+ cb(url, file)
+ end
end)
end