Skip to content

Commit

Permalink
WIP 5
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jul 26, 2021
1 parent e87bc42 commit c738c7a
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/gridcoin/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ void Upgrade::DownloadSnapshot()
error("%s: Exception occurred while attempting to download snapshot (%s)", __func__, e.what());

DownloadStatus.SetSnapshotDownloadFailed(true);

return;
}

LogPrint(BCLog::LogFlags::VERBOSE, "INFO: %s: Snapshot download complete.", __func__);
Expand All @@ -404,6 +406,10 @@ void Upgrade::VerifySHA256SUM()
{
error("%s: Exception occurred while attempting to retrieve snapshot SHA256SUM (%s)",
__func__, e.what());

DownloadStatus.SetSHA256SUMFailed(true);

return;
}

if (ServerSHA256SUM.empty())
Expand Down Expand Up @@ -459,6 +465,7 @@ void Upgrade::VerifySHA256SUM()
{
LogPrint(BCLog::LogFlags::VERBOSE, "INFO %s: SHA256SUM verification successful.", __func__);

DownloadStatus.SetSHA256SUMProgress(100);
DownloadStatus.SetSHA256SUMComplete(true);

return;
Expand All @@ -478,11 +485,20 @@ void Upgrade::CleanupBlockchainData()
{
fs::path CleanupPath = GetDataDir();

if (fs::is_symlink(CleanupPath))
{
LogPrintf("INFO: %s: Data directory is a symlink. True path is %s.",
__func__, fs::read_symlink(CleanupPath).string());

CleanupPath = fs::read_symlink(CleanupPath);
}

unsigned int total_items = 0;
unsigned int items = 0;

// We must delete previous blockchain data
// txleveldb
// accrual
// blk*.dat
fs::directory_iterator IterEnd;

Expand Down Expand Up @@ -545,6 +561,8 @@ void Upgrade::CleanupBlockchainData()

if (!total_items)
{
// Nothing to clean up!

DownloadStatus.SetCleanupBlockchainDataComplete(true);

return;
Expand Down Expand Up @@ -652,37 +670,16 @@ void Upgrade::ExtractSnapshot()
{
try
{
// The reason for this ifdef mess is libzip and win32 (at least with libzip 1.32) don't play well together.
// I would prefer to use the CAutoFile structure, which auto-closes files when they fall out of scope and
// deals with unicode filenames properly. However on Windows, zip_open_from_source is not working properly.
//
// For right now, for Win32, we degrade to using the zip_open directly from the filename. Unfortunately this
// means that paths with special Unicode characters may not work properly, because zip_open expects a const char*.
//
// TODO: Research whether this bug has been resolved in the latest version of libzip, and then solve the cmake
// build issues with that for the depends build system.

zip_error_t* err = new zip_error_t;
struct zip* ZipArchive;

#ifdef WIN32
std::string archive_file_string = (GetDataDir() / "snapshot.zip").string();
const char* archive_file = archive_file_string.c_str();

int ze;

ZipArchive = zip_open(archive_file, 0, &ze);
zip_error_init_with_code(err, ze);
#else
fs::path archive_path = GetDataDir() / "snapshot.zip";

CAutoFile archive_file(fsbridge::fopen(archive_path, "rb"), SER_DISK, CLIENT_VERSION);

zip_error_init(err);

zip_source_t* zip_source = zip_source_filep_create(archive_file.Get(), 0, -1, err);
ZipArchive = zip_open_from_source(zip_source, 0, err);
#endif

if (ZipArchive == nullptr)
{
Expand Down Expand Up @@ -765,6 +762,7 @@ void Upgrade::ExtractSnapshot()
while ((uint64_t) sum < ZipStat.size)
{
int64_t len = 0;
// Note that using a buffer larger than this risks crashes on macOS.
char Buf[256*1024];

boost::this_thread::interruption_point();
Expand Down

0 comments on commit c738c7a

Please sign in to comment.