Add progress bar for migrations
This commit is contained in:
parent
67e9885d10
commit
0b9fd31dc3
@ -3,6 +3,7 @@
|
|||||||
#include "KnownBlockVersions.h"
|
#include "KnownBlockVersions.h"
|
||||||
#include <cpp-utils/data/SerializationHelper.h>
|
#include <cpp-utils/data/SerializationHelper.h>
|
||||||
#include <cpp-utils/process/SignalCatcher.h>
|
#include <cpp-utils/process/SignalCatcher.h>
|
||||||
|
#include <cpp-utils/io/ProgressBar.h>
|
||||||
|
|
||||||
using cpputils::Data;
|
using cpputils::Data;
|
||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
@ -199,15 +200,16 @@ void IntegrityBlockStore2::forEachBlock(std::function<void (const BlockId &)> ca
|
|||||||
void IntegrityBlockStore2::migrateFromBlockstoreWithoutVersionNumbers(BlockStore2 *baseBlockStore, const boost::filesystem::path &integrityFilePath, uint32_t myClientId) {
|
void IntegrityBlockStore2::migrateFromBlockstoreWithoutVersionNumbers(BlockStore2 *baseBlockStore, const boost::filesystem::path &integrityFilePath, uint32_t myClientId) {
|
||||||
SignalCatcher signalCatcher;
|
SignalCatcher signalCatcher;
|
||||||
|
|
||||||
std::cout << "Migrating file system for integrity features. Please don't interrupt this process. This can take a while..." << std::flush;
|
|
||||||
KnownBlockVersions knownBlockVersions(integrityFilePath, myClientId);
|
KnownBlockVersions knownBlockVersions(integrityFilePath, myClientId);
|
||||||
baseBlockStore->forEachBlock([&baseBlockStore, &knownBlockVersions, &signalCatcher] (const BlockId &blockId) {
|
uint64_t numProcessedBlocks = 0;
|
||||||
|
cpputils::ProgressBar progressbar("Migrating file system for integrity features. This can take a while...", baseBlockStore->numBlocks());
|
||||||
|
baseBlockStore->forEachBlock([&] (const BlockId &blockId) {
|
||||||
if (signalCatcher.signal_occurred()) {
|
if (signalCatcher.signal_occurred()) {
|
||||||
throw std::runtime_error("Caught signal");
|
throw std::runtime_error("Caught signal");
|
||||||
}
|
}
|
||||||
migrateBlockFromBlockstoreWithoutVersionNumbers(baseBlockStore, blockId, &knownBlockVersions);
|
migrateBlockFromBlockstoreWithoutVersionNumbers(baseBlockStore, blockId, &knownBlockVersions);
|
||||||
|
progressbar.update(++numProcessedBlocks);
|
||||||
});
|
});
|
||||||
std::cout << "done" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrityBlockStore2::migrateBlockFromBlockstoreWithoutVersionNumbers(blockstore::BlockStore2* baseBlockStore, const blockstore::BlockId& blockId, KnownBlockVersions *knownBlockVersions) {
|
void IntegrityBlockStore2::migrateBlockFromBlockstoreWithoutVersionNumbers(blockstore::BlockStore2* baseBlockStore, const blockstore::BlockId& blockId, KnownBlockVersions *knownBlockVersions) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "DirBlob.h"
|
#include "DirBlob.h"
|
||||||
#include "SymlinkBlob.h"
|
#include "SymlinkBlob.h"
|
||||||
#include <cryfs/config/CryConfigFile.h>
|
#include <cryfs/config/CryConfigFile.h>
|
||||||
|
#include <cpp-utils/io/ProgressBar.h>
|
||||||
#include <cpp-utils/process/SignalCatcher.h>
|
#include <cpp-utils/process/SignalCatcher.h>
|
||||||
|
|
||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
@ -42,15 +43,19 @@ boost::optional<unique_ref<FsBlob>> FsBlobStore::load(const blockstore::BlockId
|
|||||||
|
|
||||||
auto fsBlobStore = make_unique_ref<FsBlobStore>(std::move(blobStore));
|
auto fsBlobStore = make_unique_ref<FsBlobStore>(std::move(blobStore));
|
||||||
|
|
||||||
std::cout << "Migrating file system for conflict resolution features. Please don't interrupt this process. This can take a while..." << std::flush;
|
uint64_t migratedBlocks = 0;
|
||||||
fsBlobStore->_migrate(std::move(*rootBlob), blockstore::BlockId::Null(), &signalCatcher);
|
cpputils::ProgressBar progressbar("Migrating file system for conflict resolution features. This can take a while...", fsBlobStore->numBlocks());
|
||||||
std::cout << "done" << std::endl;
|
fsBlobStore->_migrate(std::move(*rootBlob), blockstore::BlockId::Null(), &signalCatcher, [&] (uint32_t numNodes) {
|
||||||
|
migratedBlocks += numNodes;
|
||||||
|
progressbar.update(migratedBlocks);
|
||||||
|
});
|
||||||
|
|
||||||
return fsBlobStore;
|
return fsBlobStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FsBlobStore::_migrate(unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId, SignalCatcher* signalCatcher) {
|
void FsBlobStore::_migrate(unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId, SignalCatcher* signalCatcher, std::function<void(uint32_t numNodes)> perBlobCallback) {
|
||||||
FsBlobView::migrate(node.get(), parentId);
|
FsBlobView::migrate(node.get(), parentId);
|
||||||
|
perBlobCallback(node->numNodes());
|
||||||
if (FsBlobView::blobType(*node) == FsBlobView::BlobType::DIR) {
|
if (FsBlobView::blobType(*node) == FsBlobView::BlobType::DIR) {
|
||||||
DirBlob dir(std::move(node), _getLstatSize());
|
DirBlob dir(std::move(node), _getLstatSize());
|
||||||
vector<fspp::Dir::Entry> children;
|
vector<fspp::Dir::Entry> children;
|
||||||
@ -64,7 +69,7 @@ boost::optional<unique_ref<FsBlob>> FsBlobStore::load(const blockstore::BlockId
|
|||||||
ASSERT(childEntry != none, "Couldn't load child, although it was returned as a child in the list.");
|
ASSERT(childEntry != none, "Couldn't load child, although it was returned as a child in the list.");
|
||||||
auto childBlob = _baseBlobStore->load(childEntry->blockId());
|
auto childBlob = _baseBlobStore->load(childEntry->blockId());
|
||||||
ASSERT(childBlob != none, "Couldn't load child blob");
|
ASSERT(childBlob != none, "Couldn't load child blob");
|
||||||
_migrate(std::move(*childBlob), dir.blockId(), signalCatcher);
|
_migrate(std::move(*childBlob), dir.blockId(), signalCatcher, perBlobCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ namespace cryfs {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
#ifndef CRYFS_NO_COMPATIBILITY
|
#ifndef CRYFS_NO_COMPATIBILITY
|
||||||
void _migrate(cpputils::unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId, cpputils::SignalCatcher* signalCatcher);
|
void _migrate(cpputils::unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId, cpputils::SignalCatcher* signalCatcher, std::function<void(uint32_t numNodes)> perBlobCallback);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::function<fspp::num_bytes_t(const blockstore::BlockId &)> _getLstatSize();
|
std::function<fspp::num_bytes_t(const blockstore::BlockId &)> _getLstatSize();
|
||||||
|
Loading…
Reference in New Issue
Block a user