commit db203e9508242bfe3272e2e6989934d9b56979c9
parent 88f6da4f4b67c71ca2600c95e5f614443d1d8199
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 7 Dec 2018 21:49:32 -0500
add a checksum attribute to the <source> index tag
Diffstat:
4 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/src/index_v1.cpp b/src/index_v1.cpp
@@ -176,6 +176,9 @@ void LoadSourceV1(TiXmlElement *node, Version *ver)
const char *file = node->Attribute("file");
if(!file) file = "";
+ const char *checksum = node->Attribute("checksum");
+ if(!checksum) checksum = "";
+
const char *main = node->Attribute("main");
if(!main) main = "";
@@ -185,6 +188,7 @@ void LoadSourceV1(TiXmlElement *node, Version *ver)
Source *src = new Source(file, url, ver);
unique_ptr<Source> ptr(src);
+ src->setChecksum(checksum);
src->setPlatform(platform);
src->setTypeOverride(Package::getType(type));
diff --git a/src/source.hpp b/src/source.hpp
@@ -42,25 +42,31 @@ public:
static Section detectSection(const Path &category);
Source(const std::string &file, const std::string &url, const Version *);
+
const Version *version() const { return m_version; }
+ Package::Type type() const;
+ const std::string &file() const;
+ const std::string &url() const { return m_url; }
+ Path targetPath() const;
+
+ void setChecksum(const std::string &checksum) { m_checksum = checksum; }
+ const std::string &checksum() const { return m_checksum; }
void setPlatform(Platform p) { m_platform = p; }
Platform platform() const { return m_platform; }
+
void setTypeOverride(Package::Type t) { m_type = t; }
Package::Type typeOverride() const { return m_type; }
- Package::Type type() const;
- const std::string &file() const;
- const std::string &url() const { return m_url; }
+
void setSections(int);
int sections() const { return m_sections; }
- Path targetPath() const;
-
private:
Platform m_platform;
Package::Type m_type;
std::string m_file;
std::string m_url;
+ std::string m_checksum;
int m_sections;
Path m_targetPath;
const Version *m_version;
diff --git a/test/index_v1.cpp b/test/index_v1.cpp
@@ -302,3 +302,22 @@ TEST_CASE("read multiple sections", M) {
REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->sections()
== (Source::MainSection | Source::MIDIEditorSection));
}
+
+TEST_CASE("read sha256 checksum", M) {
+ IndexPtr ri = Index::load({}, R"(
+<index version="1">
+ <category name="catname">
+ <reapack name="packname" type="script">
+ <version name="1.0" author="John Doe">
+ <source checksum="12206037d8b51b33934348a2b26e04f0eb7227315b87bb5688ceb6dccb0468b14cce">https://google.com/</source>
+ </version>
+ </reapack>
+ </category>
+</index>
+ )");
+
+ REQUIRE(ri->packages().size() == 1);
+
+ REQUIRE(ri->category(0)->package(0)->version(0)->source(0)->checksum()
+ == "12206037d8b51b33934348a2b26e04f0eb7227315b87bb5688ceb6dccb0468b14cce");
+}
diff --git a/test/source.cpp b/test/source.cpp
@@ -204,3 +204,13 @@ TEST_CASE("directory traversal in category name", M) {
REQUIRE(src.targetPath() == expected);
}
+
+TEST_CASE("source checksum", M) {
+ MAKE_VERSION;
+
+ Source src({}, "url", &ver);
+ REQUIRE(src.checksum().empty());
+
+ src.setChecksum("hello world");
+ REQUIRE(src.checksum() == "hello world");
+}