_directory = 0;
abort("Repository cancelled request");
}
+
+ size_t contentSize() const
+ {
+ return _contentSize;
+ }
+
+ void setContentSize(size_t sz)
+ {
+ _contentSize = sz;
+ }
protected:
HTTPDirectory* _directory;
+ size_t _contentSize;
};
typedef SGSharedPtr<HTTPRepoGetRequest> RepoRequestPtr;
HTTPRepoPrivate(HTTPRepository* parent) :
p(parent),
isUpdating(false),
- status(AbstractRepository::REPO_NO_ERROR)
+ status(AbstractRepository::REPO_NO_ERROR),
+ totalDownloaded(0)
{ ; }
~HTTPRepoPrivate();
bool isUpdating;
AbstractRepository::ResultCode status;
HTTPDirectory* rootDir;
+ size_t totalDownloaded;
- HTTP::Request_ptr updateFile(HTTPDirectory* dir, const std::string& name);
- HTTP::Request_ptr updateDir(HTTPDirectory* dir, const std::string& hash);
+ HTTP::Request_ptr updateFile(HTTPDirectory* dir, const std::string& name,
+ size_t sz);
+ HTTP::Request_ptr updateDir(HTTPDirectory* dir, const std::string& hash,
+ size_t sz);
std::string hashForPath(const SGPath& p);
void updatedFileContents(const SGPath& p, const std::string& newHash);
if (p.exists()) {
try {
// already exists on disk
- bool ok = parseDirIndex(children);
+ parseDirIndex(children);
std::sort(children.begin(), children.end());
} catch (sg_exception& e) {
// parsing cache failed
}
if (cit->type == ChildInfo::FileType) {
- _repository->updateFile(this, *it);
+ _repository->updateFile(this, *it, cit->sizeInBytes);
} else {
SGPath p(relativePath());
p.append(*it);
HTTPDirectory* childDir = _repository->getOrCreateDirectory(p.str());
- _repository->updateDir(childDir, cit->hash);
+ _repository->updateDir(childDir, cit->hash, cit->sizeInBytes);
}
}
}
return _relativePath;
}
- void didUpdateFile(const std::string& file, const std::string& hash)
+ void didUpdateFile(const std::string& file, const std::string& hash, size_t sz)
{
// check hash matches what we expected
ChildInfoList::iterator it = findIndexChild(file);
_repository->failedToUpdateChild(_relativePath, AbstractRepository::REPO_ERROR_CHECKSUM);
} else {
_repository->updatedFileContents(fpath, hash);
+ _repository->totalDownloaded += sz;
//SG_LOG(SG_TERRASYNC, SG_INFO, "did update:" << fpath);
} // of hash matches
} // of found in child list
_d->status = REPO_NO_ERROR;
_d->isUpdating = true;
_d->failures.clear();
- _d->updateDir(_d->rootDir, std::string());
+ _d->updateDir(_d->rootDir, std::string(), 0);
}
bool HTTPRepository::isDoingSync() const
return _d->isUpdating;
}
+size_t HTTPRepository::bytesToDownload() const
+{
+ size_t result = 0;
+
+ HTTPRepoPrivate::RequestVector::const_iterator r;
+ for (r = _d->requests.begin(); r != _d->requests.end(); ++r) {
+ result += (*r)->contentSize() - (*r)->responseBytesReceived();
+ }
+
+ return result;
+}
+
+size_t HTTPRepository::bytesDownloaded() const
+{
+ size_t result = _d->totalDownloaded;
+
+ HTTPRepoPrivate::RequestVector::const_iterator r;
+ for (r = _d->requests.begin(); r != _d->requests.end(); ++r) {
+ result += (*r)->responseBytesReceived();
+ }
+
+ return result;
+}
+
AbstractRepository::ResultCode
HTTPRepository::failure() const
{
file->close();
if (responseCode() == 200) {
std::string hash = strutils::encodeHex(sha1_result(&hashContext), HASH_LENGTH);
- _directory->didUpdateFile(fileName, hash);
+ _directory->didUpdateFile(fileName, hash, contentSize());
//SG_LOG(SG_TERRASYNC, SG_INFO, "got file " << fileName << " in " << _directory->absolutePath());
} else if (responseCode() == 404) {
_directory->didFailToUpdateFile(fileName, AbstractRepository::REPO_ERROR_FILE_NOT_FOUND);
//SG_LOG(SG_TERRASYNC, SG_INFO, "updated dir index " << _directory->absolutePath());
}
+ _directory->repository()->totalDownloaded += contentSize();
+
try {
// either way we've confirmed the index is valid so update
// children now
}
}
- HTTP::Request_ptr HTTPRepoPrivate::updateFile(HTTPDirectory* dir, const std::string& name)
+ HTTP::Request_ptr HTTPRepoPrivate::updateFile(HTTPDirectory* dir, const std::string& name, size_t sz)
{
RepoRequestPtr r(new FileGetRequest(dir, name));
+ r->setContentSize(sz);
requests.push_back(r);
http->makeRequest(r);
return r;
}
- HTTP::Request_ptr HTTPRepoPrivate::updateDir(HTTPDirectory* dir, const std::string& hash)
+ HTTP::Request_ptr HTTPRepoPrivate::updateDir(HTTPDirectory* dir, const std::string& hash, size_t sz)
{
RepoRequestPtr r(new DirGetRequest(dir, hash));
+ r->setContentSize(sz);
requests.push_back(r);
http->makeRequest(r);
return r;