commit 055f3fb32ae89312b28499a57e275b08f19f7c06
parent 9b5257a9adceb89e1a39182bfdc0e899dca9b147
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 28 Mar 2017 21:34:07 -0400
archive: list missing files on export if any
Diffstat:
3 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/archive.cpp b/src/archive.cpp
@@ -246,7 +246,8 @@ void FileExtractor::run(DownloadContext *)
finish(Success);
}
-size_t Archive::create(const auto_string &path, ThreadPool *pool, ReaPack *reapack)
+size_t Archive::create(const auto_string &path, vector<string> *errors,
+ ThreadPool *pool, ReaPack *reapack)
{
size_t count = 0;
vector<ThreadTask *> jobs;
@@ -256,6 +257,15 @@ size_t Archive::create(const auto_string &path, ThreadPool *pool, ReaPack *reapa
ArchiveWriterPtr writer = make_shared<ArchiveWriter>(path);
+ const auto compress = [&] (const Path &path) {
+ if(FS::exists(path))
+ jobs.push_back(new FileCompressor(path, writer));
+ else {
+ const auto fmt = format("%s (%s)") % path.join() % FS::lastError();
+ errors->push_back(fmt.str());
+ }
+ };
+
for(const Remote &remote : reapack->config()->remotes.getEnabled()) {
bool addedRemote = false;
@@ -264,7 +274,7 @@ size_t Archive::create(const auto_string &path, ThreadPool *pool, ReaPack *reapa
if(!addedRemote) {
toc << "REPO " << remote.toString() << '\n';
- jobs.push_back(new FileCompressor(Index::pathFor(remote.name()), writer));
+ compress(Index::pathFor(remote.name()));
addedRemote = true;
}
@@ -276,13 +286,15 @@ size_t Archive::create(const auto_string &path, ThreadPool *pool, ReaPack *reapa
;
for(const Registry::File &file : reg.getFiles(entry))
- jobs.push_back(new FileCompressor(file.path, writer));
+ compress(file.path);
}
}
writer->addFile(ARCHIVE_TOC, toc);
- // start after we've written the table of contents in the main thread
+ // Start after we've written the table of contents in the main thread
+ // because we cannot safely write into the zip from more than one
+ // thread at the same time.
for(ThreadTask *job : jobs)
pool->push(job);
diff --git a/src/archive.hpp b/src/archive.hpp
@@ -29,7 +29,8 @@ typedef void *zipFile;
namespace Archive {
void import(const auto_string &path, ReaPack *);
- size_t create(const auto_string &path, ThreadPool *pool, ReaPack *);
+ size_t create(const auto_string &path,
+ std::vector<std::string> *errors, ThreadPool *pool, ReaPack *);
};
class ArchiveReader {
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -31,6 +31,8 @@
#include "resource.hpp"
#include "transaction.hpp"
+#include <boost/algorithm/string/join.hpp>
+
static const auto_char *ARCHIVE_FILTER =
AUTO_STR("ReaPack Offline Archive (*.ReaPackArchive)\0*.ReaPackArchive\0");
static const auto_char *ARCHIVE_EXT = AUTO_STR("ReaPackArchive");
@@ -520,15 +522,27 @@ void Manager::exportArchive()
Dialog *progress = Dialog::Create<Progress>(instance(), parent(), pool);
try {
- const size_t count = Archive::create(path, pool, m_reapack);
+ vector<string> errors;
+ const size_t count = Archive::create(path, &errors, pool, m_reapack);
const auto finish = [=] {
Dialog::Destroy(progress);
- auto_char msg[255];
+ auto_char error[1024];
+ if(errors.empty())
+ error[0] = 0;
+ else {
+ auto_snprintf(error, auto_size(error),
+ AUTO_STR("\r\n\r\n%zu file%s could not be archived. ")
+ AUTO_STR("Synchronize packages to repair any missing file.\r\n\r\n%s"),
+ errors.size(), errors.size() == 1 ? AUTO_STR("") : AUTO_STR("s"),
+ make_autostring(boost::algorithm::join(errors, "\r\n")).c_str());
+ }
+
+ auto_char msg[2048];
auto_snprintf(msg, auto_size(msg),
- AUTO_STR("Done! %zu package%s were exported in the archive."),
- count, count == 1 ? AUTO_STR("") : AUTO_STR("s"));
+ AUTO_STR("Done! %zu package%s were exported in the archive.%s"),
+ count, count == 1 ? AUTO_STR("") : AUTO_STR("s"), error);
MessageBox(handle(), msg, title, MB_OK);
delete pool;
@@ -552,7 +566,6 @@ void Manager::exportArchive()
);
MessageBox(handle(), msg, title, MB_OK);
}
-
}
void Manager::launchBrowser()