TerraSync: fix local-file copying

Avoid downloading data corresponding to files shipped in FGData.
This commit is contained in:
James Turner 2020-11-04 11:22:48 +00:00
parent f34a4a304e
commit 537776e1f8
2 changed files with 46 additions and 35 deletions

View File

@ -221,42 +221,48 @@ public:
char* buf = nullptr;
size_t bufSize = 0;
for (const auto& child : children) {
if (child.type != HTTPRepository::FileType)
continue;
for (auto &child : children) {
if (child.type != HTTPRepository::FileType)
continue;
if (child.path.exists())
continue;
if (child.path.exists())
continue;
SGPath cp = _repository->installedCopyPath;
cp.append(relativePath());
cp.append(child.name);
if (!cp.exists()) {
continue;
}
SGPath cp = _repository->installedCopyPath;
cp.append(relativePath());
cp.append(child.name);
if (!cp.exists()) {
continue;
}
SGBinaryFile src(cp);
SGBinaryFile dst(child.path);
src.open(SG_IO_IN);
dst.open(SG_IO_OUT);
SGBinaryFile src(cp);
SGBinaryFile dst(child.path);
src.open(SG_IO_IN);
dst.open(SG_IO_OUT);
if (bufSize < cp.sizeInBytes()) {
bufSize = cp.sizeInBytes();
free(buf);
buf = (char*) malloc(bufSize);
if (!buf) {
continue;
}
}
if (bufSize < cp.sizeInBytes()) {
bufSize = cp.sizeInBytes();
free(buf);
buf = (char *)malloc(bufSize);
if (!buf) {
continue;
}
}
src.read(buf, cp.sizeInBytes());
dst.write(buf, cp.sizeInBytes());
src.close();
dst.close();
src.read(buf, cp.sizeInBytes());
dst.write(buf, cp.sizeInBytes());
src.close();
dst.close();
}
// reset caching
child.path.set_cached(false);
child.path.set_cached(true);
free(buf);
std::string hash = computeHashForPath(child.path);
updatedFileContents(child.path, hash);
}
free(buf);
}
void updateChildrenBasedOnHash()

View File

@ -603,12 +603,6 @@ void SGTerraSync::WorkerThread::updateSyncSlot(SyncSlot &slot)
beginNormalSync(slot);
}
if (_installRoot.exists()) {
SGPath p = _installRoot;
p.append(slot.currentItem._dir);
slot.repository->setInstalledCopyPath(p);
}
try {
slot.repository->update();
} catch (sg_exception& e) {
@ -676,6 +670,11 @@ void SGTerraSync::WorkerThread::beginSyncTile(SyncSlot& slot)
slot.repository.reset(new HTTPRepository(path, &_http));
slot.repository->setBaseUrl(_httpServer + "/" + tileCategory);
if (_installRoot.exists()) {
SGPath p = _installRoot / tileCategory;
slot.repository->setInstalledCopyPath(p);
}
const auto dirPrefix = tenByTenDir + "/" + oneByOneDir;
// filter callback to *only* sync the 1x1 dir we want, if it exists
@ -706,6 +705,12 @@ void SGTerraSync::WorkerThread::beginNormalSync(SyncSlot& slot)
path.append(slot.currentItem._dir);
slot.repository.reset(new HTTPRepository(path, &_http));
slot.repository->setBaseUrl(_httpServer + "/" + slot.currentItem._dir);
if (_installRoot.exists()) {
SGPath p = _installRoot;
p.append(slot.currentItem._dir);
slot.repository->setInstalledCopyPath(p);
}
}
void SGTerraSync::WorkerThread::runInternal()