From 29e4c12898b232ec7c3af563f27aa1f5638fe0da Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 20 May 2025 20:29:31 -0700 Subject: use temp file during download --- downloader.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'downloader.lua') diff --git a/downloader.lua b/downloader.lua index 67fb675..7fee596 100644 --- a/downloader.lua +++ b/downloader.lua @@ -19,8 +19,9 @@ function mt:exec(url, file, cb) return end - local cmd = {'curl', '-sSfLo', file, url} - print('exec: ' .. utils.to_string(cmd)) + local tmp = file .. '.tmp' + local cmd = {'curl', '-sSfLo', tmp, url} + print('downloading ' .. url) self.running = true mp.command_native_async({ @@ -30,8 +31,13 @@ function mt:exec(url, file, cb) }, function(success, res) self.running = false self:exec_next() - if cb and success and res.status == 0 then - cb(url, file) + if success and res.status == 0 then + os.rename(tmp, file) + if cb then + cb(url, file) + end + else + os.remove(tmp) end end) end -- cgit v1.2.3-70-g09d2