AbstractRepository interface removed.
This commit is contained in:
@@ -1,34 +0,0 @@
|
|||||||
// AbstractRepository.cxx -- abstract API for TerraSync remote
|
|
||||||
//
|
|
||||||
// Copyright (C) 2016 James Turner <zakalawe@mac.com>
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
#include "AbstractRepository.hxx"
|
|
||||||
|
|
||||||
namespace simgear
|
|
||||||
{
|
|
||||||
|
|
||||||
AbstractRepository::~AbstractRepository()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t AbstractRepository::bytesStillToDownload() const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // of namespace simgear
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
// AbstractRepository.hxx - API for terrasyc to access remote server
|
|
||||||
//
|
|
||||||
// Copyright (C) 2016 James Turner <zakalawe@mac.com>
|
|
||||||
//
|
|
||||||
// This program is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU General Public License as
|
|
||||||
// published by the Free Software Foundation; either version 2 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SG_IO_ABSTRACT_REPOSITORY_HXX
|
|
||||||
#define SG_IO_ABSTRACT_REPOSITORY_HXX
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <simgear/misc/sg_path.hxx>
|
|
||||||
|
|
||||||
namespace simgear {
|
|
||||||
|
|
||||||
namespace HTTP {
|
|
||||||
class Client;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AbstractRepository
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual ~AbstractRepository();
|
|
||||||
|
|
||||||
virtual SGPath fsBase() const = 0;
|
|
||||||
|
|
||||||
virtual void setBaseUrl(const std::string& url) =0;
|
|
||||||
virtual std::string baseUrl() const = 0;;
|
|
||||||
|
|
||||||
virtual HTTP::Client* http() const = 0;
|
|
||||||
|
|
||||||
virtual void update() = 0;
|
|
||||||
|
|
||||||
virtual bool isDoingSync() const = 0;
|
|
||||||
|
|
||||||
virtual size_t bytesStillToDownload() const;
|
|
||||||
|
|
||||||
enum ResultCode {
|
|
||||||
REPO_NO_ERROR = 0,
|
|
||||||
REPO_ERROR_NOT_FOUND,
|
|
||||||
REPO_ERROR_SOCKET,
|
|
||||||
SVN_ERROR_XML,
|
|
||||||
SVN_ERROR_TXDELTA,
|
|
||||||
REPO_ERROR_IO,
|
|
||||||
REPO_ERROR_CHECKSUM,
|
|
||||||
REPO_ERROR_FILE_NOT_FOUND,
|
|
||||||
REPO_ERROR_HTTP,
|
|
||||||
REPO_PARTIAL_UPDATE
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ResultCode failure() const = 0;
|
|
||||||
protected:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // of namespace simgear
|
|
||||||
|
|
||||||
#endif // of SG_IO_ABSTRACT_REPOSITORY_HXX
|
|
||||||
@@ -18,7 +18,6 @@ set(HEADERS
|
|||||||
HTTPFileRequest.hxx
|
HTTPFileRequest.hxx
|
||||||
HTTPMemoryRequest.hxx
|
HTTPMemoryRequest.hxx
|
||||||
HTTPRequest.hxx
|
HTTPRequest.hxx
|
||||||
AbstractRepository.hxx
|
|
||||||
HTTPRepository.hxx
|
HTTPRepository.hxx
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@ set(SOURCES
|
|||||||
HTTPFileRequest.cxx
|
HTTPFileRequest.cxx
|
||||||
HTTPMemoryRequest.cxx
|
HTTPMemoryRequest.cxx
|
||||||
HTTPRequest.cxx
|
HTTPRequest.cxx
|
||||||
AbstractRepository.cxx
|
|
||||||
HTTPRepository.cxx
|
HTTPRepository.cxx
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public:
|
|||||||
struct Failure
|
struct Failure
|
||||||
{
|
{
|
||||||
SGPath path;
|
SGPath path;
|
||||||
AbstractRepository::ResultCode error;
|
HTTPRepository::ResultCode error;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<Failure> FailureList;
|
typedef std::vector<Failure> FailureList;
|
||||||
@@ -104,7 +104,7 @@ public:
|
|||||||
hashCacheDirty(false),
|
hashCacheDirty(false),
|
||||||
p(parent),
|
p(parent),
|
||||||
isUpdating(false),
|
isUpdating(false),
|
||||||
status(AbstractRepository::REPO_NO_ERROR),
|
status(HTTPRepository::REPO_NO_ERROR),
|
||||||
totalDownloaded(0)
|
totalDownloaded(0)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public:
|
|||||||
std::string baseUrl;
|
std::string baseUrl;
|
||||||
SGPath basePath;
|
SGPath basePath;
|
||||||
bool isUpdating;
|
bool isUpdating;
|
||||||
AbstractRepository::ResultCode status;
|
HTTPRepository::ResultCode status;
|
||||||
HTTPDirectory* rootDir;
|
HTTPDirectory* rootDir;
|
||||||
size_t totalDownloaded;
|
size_t totalDownloaded;
|
||||||
|
|
||||||
@@ -130,9 +130,9 @@ public:
|
|||||||
std::string computeHashForPath(const SGPath& p);
|
std::string computeHashForPath(const SGPath& p);
|
||||||
void writeHashCache();
|
void writeHashCache();
|
||||||
|
|
||||||
void failedToGetRootIndex(AbstractRepository::ResultCode st);
|
void failedToGetRootIndex(HTTPRepository::ResultCode st);
|
||||||
void failedToUpdateChild(const SGPath& relativePath,
|
void failedToUpdateChild(const SGPath& relativePath,
|
||||||
AbstractRepository::ResultCode fileStatus);
|
HTTPRepository::ResultCode fileStatus);
|
||||||
|
|
||||||
typedef std::vector<RepoRequestPtr> RequestVector;
|
typedef std::vector<RepoRequestPtr> RequestVector;
|
||||||
RequestVector queuedRequests,
|
RequestVector queuedRequests,
|
||||||
@@ -237,7 +237,7 @@ public:
|
|||||||
std::sort(children.begin(), children.end());
|
std::sort(children.begin(), children.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void failedToUpdate(AbstractRepository::ResultCode status)
|
void failedToUpdate(HTTPRepository::ResultCode status)
|
||||||
{
|
{
|
||||||
if (_relativePath.isNull()) {
|
if (_relativePath.isNull()) {
|
||||||
// root dir failed
|
// root dir failed
|
||||||
@@ -365,7 +365,7 @@ public:
|
|||||||
fpath.append(file);
|
fpath.append(file);
|
||||||
|
|
||||||
if (it->hash != hash) {
|
if (it->hash != hash) {
|
||||||
_repository->failedToUpdateChild(_relativePath, AbstractRepository::REPO_ERROR_CHECKSUM);
|
_repository->failedToUpdateChild(_relativePath, HTTPRepository::REPO_ERROR_CHECKSUM);
|
||||||
} else {
|
} else {
|
||||||
_repository->updatedFileContents(fpath, hash);
|
_repository->updatedFileContents(fpath, hash);
|
||||||
_repository->totalDownloaded += sz;
|
_repository->totalDownloaded += sz;
|
||||||
@@ -375,7 +375,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void didFailToUpdateFile(const std::string& file,
|
void didFailToUpdateFile(const std::string& file,
|
||||||
AbstractRepository::ResultCode status)
|
HTTPRepository::ResultCode status)
|
||||||
{
|
{
|
||||||
SGPath fpath(_relativePath);
|
SGPath fpath(_relativePath);
|
||||||
fpath.append(file);
|
fpath.append(file);
|
||||||
@@ -580,7 +580,7 @@ size_t HTTPRepository::bytesDownloaded() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractRepository::ResultCode
|
HTTPRepository::ResultCode
|
||||||
HTTPRepository::failure() const
|
HTTPRepository::failure() const
|
||||||
{
|
{
|
||||||
if ((_d->status == REPO_NO_ERROR) && !_d->failures.empty()) {
|
if ((_d->status == REPO_NO_ERROR) && !_d->failures.empty()) {
|
||||||
@@ -634,10 +634,10 @@ HTTPRepository::failure() const
|
|||||||
SG_LOG(SG_TERRASYNC, SG_DEBUG, "got file " << fileName << " in " << _directory->absolutePath());
|
SG_LOG(SG_TERRASYNC, SG_DEBUG, "got file " << fileName << " in " << _directory->absolutePath());
|
||||||
} else if (responseCode() == 404) {
|
} else if (responseCode() == 404) {
|
||||||
SG_LOG(SG_TERRASYNC, SG_WARN, "terrasync file not found on server: " << fileName << " for " << _directory->absolutePath());
|
SG_LOG(SG_TERRASYNC, SG_WARN, "terrasync file not found on server: " << fileName << " for " << _directory->absolutePath());
|
||||||
_directory->didFailToUpdateFile(fileName, AbstractRepository::REPO_ERROR_FILE_NOT_FOUND);
|
_directory->didFailToUpdateFile(fileName, HTTPRepository::REPO_ERROR_FILE_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_TERRASYNC, SG_WARN, "terrasync file download error on server: " << fileName << " for " << _directory->absolutePath() << ": " << responseCode() );
|
SG_LOG(SG_TERRASYNC, SG_WARN, "terrasync file download error on server: " << fileName << " for " << _directory->absolutePath() << ": " << responseCode() );
|
||||||
_directory->didFailToUpdateFile(fileName, AbstractRepository::REPO_ERROR_HTTP);
|
_directory->didFailToUpdateFile(fileName, HTTPRepository::REPO_ERROR_HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
_directory->repository()->finishedRequest(this);
|
_directory->repository()->finishedRequest(this);
|
||||||
@@ -651,7 +651,7 @@ HTTPRepository::failure() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_directory) {
|
if (_directory) {
|
||||||
_directory->didFailToUpdateFile(fileName, AbstractRepository::REPO_ERROR_SOCKET);
|
_directory->didFailToUpdateFile(fileName, HTTPRepository::REPO_ERROR_SOCKET);
|
||||||
_directory->repository()->finishedRequest(this);
|
_directory->repository()->finishedRequest(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -701,7 +701,7 @@ HTTPRepository::failure() const
|
|||||||
if (responseCode() == 200) {
|
if (responseCode() == 200) {
|
||||||
std::string hash = strutils::encodeHex(sha1_result(&hashContext), HASH_LENGTH);
|
std::string hash = strutils::encodeHex(sha1_result(&hashContext), HASH_LENGTH);
|
||||||
if (!_targetHash.empty() && (hash != _targetHash)) {
|
if (!_targetHash.empty() && (hash != _targetHash)) {
|
||||||
_directory->failedToUpdate(AbstractRepository::REPO_ERROR_CHECKSUM);
|
_directory->failedToUpdate(HTTPRepository::REPO_ERROR_CHECKSUM);
|
||||||
_directory->repository()->finishedRequest(this);
|
_directory->repository()->finishedRequest(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -739,12 +739,12 @@ HTTPRepository::failure() const
|
|||||||
_directory->updateChildrenBasedOnHash();
|
_directory->updateChildrenBasedOnHash();
|
||||||
SG_LOG(SG_TERRASYNC, SG_INFO, "after update of:" << _directory->absolutePath() << " child update took:" << st.elapsedMSec());
|
SG_LOG(SG_TERRASYNC, SG_INFO, "after update of:" << _directory->absolutePath() << " child update took:" << st.elapsedMSec());
|
||||||
} catch (sg_exception& ) {
|
} catch (sg_exception& ) {
|
||||||
_directory->failedToUpdate(AbstractRepository::REPO_ERROR_IO);
|
_directory->failedToUpdate(HTTPRepository::REPO_ERROR_IO);
|
||||||
}
|
}
|
||||||
} else if (responseCode() == 404) {
|
} else if (responseCode() == 404) {
|
||||||
_directory->failedToUpdate(AbstractRepository::REPO_ERROR_FILE_NOT_FOUND);
|
_directory->failedToUpdate(HTTPRepository::REPO_ERROR_FILE_NOT_FOUND);
|
||||||
} else {
|
} else {
|
||||||
_directory->failedToUpdate(AbstractRepository::REPO_ERROR_HTTP);
|
_directory->failedToUpdate(HTTPRepository::REPO_ERROR_HTTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
_directory->repository()->finishedRequest(this);
|
_directory->repository()->finishedRequest(this);
|
||||||
@@ -753,7 +753,7 @@ HTTPRepository::failure() const
|
|||||||
virtual void onFail()
|
virtual void onFail()
|
||||||
{
|
{
|
||||||
if (_directory) {
|
if (_directory) {
|
||||||
_directory->failedToUpdate(AbstractRepository::REPO_ERROR_SOCKET);
|
_directory->failedToUpdate(HTTPRepository::REPO_ERROR_SOCKET);
|
||||||
_directory->repository()->finishedRequest(this);
|
_directory->repository()->finishedRequest(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1021,14 +1021,14 @@ HTTPRepository::failure() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPRepoPrivate::failedToGetRootIndex(AbstractRepository::ResultCode st)
|
void HTTPRepoPrivate::failedToGetRootIndex(HTTPRepository::ResultCode st)
|
||||||
{
|
{
|
||||||
SG_LOG(SG_TERRASYNC, SG_WARN, "Failed to get root of repo:" << baseUrl);
|
SG_LOG(SG_TERRASYNC, SG_WARN, "Failed to get root of repo:" << baseUrl);
|
||||||
status = st;
|
status = st;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPRepoPrivate::failedToUpdateChild(const SGPath& relativePath,
|
void HTTPRepoPrivate::failedToUpdateChild(const SGPath& relativePath,
|
||||||
AbstractRepository::ResultCode fileStatus)
|
HTTPRepository::ResultCode fileStatus)
|
||||||
{
|
{
|
||||||
Failure f;
|
Failure f;
|
||||||
f.path = relativePath;
|
f.path = relativePath;
|
||||||
|
|||||||
@@ -20,16 +20,30 @@
|
|||||||
#ifndef SG_IO_HTTP_REPOSITORY_HXX
|
#ifndef SG_IO_HTTP_REPOSITORY_HXX
|
||||||
#define SG_IO_HTTP_REPOSITORY_HXX
|
#define SG_IO_HTTP_REPOSITORY_HXX
|
||||||
|
|
||||||
#include <simgear/io/AbstractRepository.hxx>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/io/HTTPClient.hxx>
|
||||||
|
|
||||||
namespace simgear {
|
namespace simgear {
|
||||||
|
|
||||||
class HTTPRepoPrivate;
|
class HTTPRepoPrivate;
|
||||||
|
|
||||||
class HTTPRepository : public AbstractRepository
|
class HTTPRepository
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum ResultCode {
|
||||||
|
REPO_NO_ERROR = 0,
|
||||||
|
REPO_ERROR_NOT_FOUND,
|
||||||
|
REPO_ERROR_SOCKET,
|
||||||
|
SVN_ERROR_XML,
|
||||||
|
SVN_ERROR_TXDELTA,
|
||||||
|
REPO_ERROR_IO,
|
||||||
|
REPO_ERROR_CHECKSUM,
|
||||||
|
REPO_ERROR_FILE_NOT_FOUND,
|
||||||
|
REPO_ERROR_HTTP,
|
||||||
|
REPO_PARTIAL_UPDATE
|
||||||
|
};
|
||||||
|
|
||||||
HTTPRepository(const SGPath& root, HTTP::Client* cl);
|
HTTPRepository(const SGPath& root, HTTP::Client* cl);
|
||||||
virtual ~HTTPRepository();
|
virtual ~HTTPRepository();
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ int main(int argc, char* argv[])
|
|||||||
SGTimeStamp::sleepForMSec(100);
|
SGTimeStamp::sleepForMSec(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repo->failure() != AbstractRepository::REPO_NO_ERROR) {
|
if (repo->failure() != HTTPRepository::REPO_NO_ERROR) {
|
||||||
cerr << "got response:" << repo->failure() << endl;
|
cerr << "got response:" << repo->failure() << endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -532,7 +532,7 @@ void testAbandonMissingFiles(HTTP::Client* cl)
|
|||||||
repo->setBaseUrl("http://localhost:2000/repo");
|
repo->setBaseUrl("http://localhost:2000/repo");
|
||||||
repo->update();
|
repo->update();
|
||||||
waitForUpdateComplete(cl, repo.get());
|
waitForUpdateComplete(cl, repo.get());
|
||||||
if (repo->failure() != AbstractRepository::REPO_PARTIAL_UPDATE) {
|
if (repo->failure() != HTTPRepository::REPO_PARTIAL_UPDATE) {
|
||||||
throw sg_exception("Bad result from missing files test");
|
throw sg_exception("Bad result from missing files test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +556,7 @@ void testAbandonCorruptFiles(HTTP::Client* cl)
|
|||||||
repo->setBaseUrl("http://localhost:2000/repo");
|
repo->setBaseUrl("http://localhost:2000/repo");
|
||||||
repo->update();
|
repo->update();
|
||||||
waitForUpdateComplete(cl, repo.get());
|
waitForUpdateComplete(cl, repo.get());
|
||||||
if (repo->failure() != AbstractRepository::REPO_PARTIAL_UPDATE) {
|
if (repo->failure() != HTTPRepository::REPO_PARTIAL_UPDATE) {
|
||||||
throw sg_exception("Bad result from corrupt files test");
|
throw sg_exception("Bad result from corrupt files test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public:
|
|||||||
SyncItem currentItem;
|
SyncItem currentItem;
|
||||||
bool isNewDirectory;
|
bool isNewDirectory;
|
||||||
std::queue<SyncItem> queue;
|
std::queue<SyncItem> queue;
|
||||||
std::auto_ptr<AbstractRepository> repository;
|
std::auto_ptr<HTTPRepository> repository;
|
||||||
SGTimeStamp stamp;
|
SGTimeStamp stamp;
|
||||||
bool busy; ///< is the slot working or idle
|
bool busy; ///< is the slot working or idle
|
||||||
|
|
||||||
@@ -446,10 +446,10 @@ void SGTerraSync::WorkerThread::updateSyncSlot(SyncSlot &slot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check result
|
// check result
|
||||||
AbstractRepository::ResultCode res = slot.repository->failure();
|
HTTPRepository::ResultCode res = slot.repository->failure();
|
||||||
if (res == AbstractRepository::REPO_ERROR_NOT_FOUND) {
|
if (res == HTTPRepository::REPO_ERROR_NOT_FOUND) {
|
||||||
notFound(slot.currentItem);
|
notFound(slot.currentItem);
|
||||||
} else if (res != AbstractRepository::REPO_NO_ERROR) {
|
} else if (res != HTTPRepository::REPO_NO_ERROR) {
|
||||||
fail(slot.currentItem);
|
fail(slot.currentItem);
|
||||||
} else {
|
} else {
|
||||||
updated(slot.currentItem, slot.isNewDirectory);
|
updated(slot.currentItem, slot.isNewDirectory);
|
||||||
|
|||||||
Reference in New Issue
Block a user