1 From c841c4a7871d2f79f9b7e2d53734f55e8410e231 Mon Sep 17 00:00:00 2001
2 From: Alexander Batischev <eual.jp@gmail.com>
3 Date: Fri, 22 Jan 2016 22:55:48 +0300
4 Subject: [PATCH] Re-download, not delete, existing files. Fixes #169
7 include/poddlthread.h | 1 +
8 src/poddlthread.cpp | 19 +++++++++++++++++--
9 2 files changed, 18 insertions(+), 2 deletions(-)
11 diff --git a/include/poddlthread.h b/include/poddlthread.h
12 index cf0f1da..99299f3 100644
13 --- a/include/poddlthread.h
14 +++ b/include/poddlthread.h
15 @@ -23,6 +23,7 @@ class poddlthread {
17 double compute_kbps();
20 void mkdir_p(const char * file);
22 std::shared_ptr<std::ofstream> f;
23 diff --git a/src/poddlthread.cpp b/src/poddlthread.cpp
24 index 3a1b390..afa6762 100644
25 --- a/src/poddlthread.cpp
26 +++ b/src/poddlthread.cpp
27 @@ -25,6 +25,13 @@ poddlthread::~poddlthread() {
30 void poddlthread::operator()() {
34 +void poddlthread::run() {
35 + // are we resuming previous download?
36 + bool resumed_download = false;
38 gettimeofday(&tv1, NULL);
41 @@ -55,11 +62,13 @@ void poddlthread::operator()() {
42 mkdir_p(dl->filename());
43 f->open(dl->filename(), std::fstream::out);
45 + resumed_download = false;
47 LOG(LOG_INFO, "poddlthread::run: stat ok: starting download from %u", sb.st_size);
48 curl_easy_setopt(easyhandle, CURLOPT_RESUME_FROM, sb.st_size);
49 dl->set_offset(sb.st_size);
50 f->open(dl->filename(), std::fstream::out | std::fstream::app);
51 + resumed_download = true;
55 @@ -75,8 +84,14 @@ void poddlthread::operator()() {
57 dl->set_status(DL_READY);
58 else if (dl->status() != DL_CANCELLED) {
59 - dl->set_status(DL_FAILED);
60 - ::unlink(dl->filename());
61 + // attempt complete re-download
62 + if (resumed_download) {
63 + ::unlink(dl->filename());
66 + dl->set_status(DL_FAILED);
67 + ::unlink(dl->filename());
71 dl->set_status(DL_FAILED);