Commit 9715d22a authored by Alexander Bock's avatar Alexander Bock
Browse files

Include the version number in the uid of the HttpSynchronization (closes #2081)

parent 2816ad4d
Showing with 18 additions and 21 deletions
+18 -21
......@@ -70,18 +70,9 @@ public:
const ghoul::Dictionary& dictionary);
/**
* Generates a unique identifying string for the dictionary that is based on the
* \c Type and the \c Identifier values of the passed \p dictionary. All other
* parameters are ignored, but as long as the \c Type and/or the \c Identifier values
* differ, the resulting string will be different.
*
* \param dictionary The dictionary containing the \c Type and the \c Identifier used
* to create a unique identifier
*
* \throw SpecificationError If the \p dictionary does not contain a \c Type, an
* \c Identifier, and a \c Name
* Generates a unique identifying string for ResourceSynchronizaiton.
*/
static std::string generateUid(const ghoul::Dictionary& dictionary);
virtual std::string generateUid() = 0;
/// Defaulted virtual constructor
virtual ~ResourceSynchronization() = default;
......
......@@ -117,6 +117,10 @@ void HttpSynchronization::cancel() {
_state = State::Unsynced;
}
std::string HttpSynchronization::generateUid() {
return fmt::format("{}/{}", _identifier, _version);
}
bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
HttpMemoryDownload fileListDownload(std::move(listUrl));
fileListDownload.onProgress([&c = _shouldCancel](int64_t, std::optional<int64_t>) {
......
......@@ -87,6 +87,8 @@ public:
/// Cancels any ongoing synchronization of this ResourceSynchronization
void cancel() override;
std::string generateUid() override;
static documentation::Documentation Documentation();
private:
......
......@@ -245,4 +245,8 @@ void UrlSynchronization::cancel() {
_state = State::Unsynced;
}
std::string UrlSynchronization::generateUid() {
return _identifier;
}
} // namespace openspace
......@@ -73,6 +73,8 @@ public:
/// Cancels any ongoing synchronization of this ResourceSynchronization
void cancel() override;
std::string generateUid() override;
static documentation::Documentation Documentation();
private:
......
......@@ -495,14 +495,13 @@ void AssetManager::setUpAssetLuaTable(Asset* asset) {
Asset* thisAsset = ghoul::lua::userData<Asset>(L, 2);
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::syncedResourceLua");
ghoul::Dictionary d = ghoul::lua::value<ghoul::Dictionary>(L);
std::string uid = ResourceSynchronization::generateUid(d);
std::unique_ptr<ResourceSynchronization> s =
ResourceSynchronization::createFromDictionary(d);
std::string uid = d.value<std::string>("Type") + "/" + s->generateUid();
SyncItem* syncItem = nullptr;
auto it = manager->_synchronizations.find(uid);
if (it == manager->_synchronizations.end()) {
std::unique_ptr<ResourceSynchronization> s =
ResourceSynchronization::createFromDictionary(d);
auto si = std::make_unique<SyncItem>();
si->synchronization = std::move(s);
si->assets.push_back(thisAsset);
......
......@@ -68,11 +68,6 @@ std::unique_ptr<ResourceSynchronization> ResourceSynchronization::createFromDict
return std::unique_ptr<ResourceSynchronization>(sync);
}
std::string ResourceSynchronization::generateUid(const ghoul::Dictionary& dictionary) {
const Parameters p = codegen::bake<Parameters>(dictionary);
return fmt::format("{}/{}", p.type, p.identifier);
}
ResourceSynchronization::ResourceSynchronization(
std::filesystem::path synchronizationRoot)
: _synchronizationRoot(std::move(synchronizationRoot))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment