13
0

FileArchive: minor fixes to get progress reporting working

This commit is contained in:
Paul Davis 2022-09-13 12:21:54 -06:00
parent be860db54f
commit 2061c3780d
2 changed files with 18 additions and 3 deletions

View File

@ -178,6 +178,12 @@ FileArchive::~FileArchive ()
} }
} }
void
FileArchive::require_progress ()
{
_req.mp.progress = this;
}
std::string std::string
FileArchive::fetch (const std::string & url, const std::string & destdir) const FileArchive::fetch (const std::string & url, const std::string & destdir) const
{ {
@ -428,7 +434,8 @@ FileArchive::do_extract (struct archive* a)
for (;;) { for (;;) {
int r = archive_read_next_header (a, &entry); int r = archive_read_next_header (a, &entry);
if (!_req.mp.progress) {
if (_req.mp.progress) {
// file i/o -- not URL // file i/o -- not URL
const uint64_t read = archive_filter_bytes (a, -1); const uint64_t read = archive_filter_bytes (a, -1);
progress (read, _req.mp.length); progress (read, _req.mp.length);
@ -460,6 +467,10 @@ FileArchive::do_extract (struct archive* a)
} }
} }
} }
if (_req.mp.progress && rv == 0) {
// file i/o -- not URL
progress (_req.mp.length, _req.mp.length);
}
archive_read_close (a); archive_read_close (a);
archive_read_free (a); archive_read_free (a);

View File

@ -18,6 +18,8 @@
#ifndef _pbd_archive_h_ #ifndef _pbd_archive_h_
#define _pbd_archive_h_ #define _pbd_archive_h_
#include <atomic>
#include <pthread.h> #include <pthread.h>
#include "pbd/signals.h" #include "pbd/signals.h"
@ -57,6 +59,8 @@ class LIBPBD_API FileArchive
PBD::Signal2<void, size_t, size_t> progress; // TODO PBD::Signal2<void, size_t, size_t> progress; // TODO
void require_progress ();
struct MemPipe { struct MemPipe {
public: public:
MemPipe () MemPipe ()
@ -100,8 +104,8 @@ class LIBPBD_API FileArchive
size_t size; size_t size;
bool done; bool done;
double processed; size_t processed;
double length; size_t length;
FileArchive* progress; FileArchive* progress;
private: private: