Packages: archive-type support in catalogs

Allow URLs which don’t encode the file extension to work
This commit is contained in:
James Turner 2018-04-27 12:07:10 +01:00
parent 8b4ace6fb8
commit 888d7fb262
5 changed files with 103 additions and 9 deletions

View File

@ -93,6 +93,11 @@ public:
}
}
// return zip data for this computed URL
if (path.find("/catalogTest1/movies") == 0) {
path = "/catalogTest1/movies-data.zip";
}
localPath.append(path);
// SG_LOG(SG_IO, SG_INFO, "local path is:" << localPath.str());
@ -152,7 +157,7 @@ int parseTest()
SG_CHECK_EQUAL(cat->description(), "First test catalog");
// check the packages too
SG_CHECK_EQUAL(cat->packages().size(), 4);
SG_CHECK_EQUAL(cat->packages().size(), 5);
pkg::PackageRef p1 = cat->packages().front();
SG_CHECK_EQUAL(p1->catalog(), cat.ptr());
@ -326,7 +331,7 @@ void testAddCatalog(HTTP::Client* cl)
p.append("org.flightgear.test.catalog1");
p.append("catalog.xml");
SG_VERIFY(p.exists());
SG_CHECK_EQUAL(root->allPackages().size(), 4);
SG_CHECK_EQUAL(root->allPackages().size(), 5);
SG_CHECK_EQUAL(root->catalogs().size(), 1);
pkg::PackageRef p1 = root->getPackageById("alpha");
@ -559,6 +564,43 @@ void testInstallTarPackage(HTTP::Client* cl)
SG_VERIFY(p.exists());
}
void testInstallArchiveType(HTTP::Client* cl)
{
global_catalogVersion = 0;
SGPath rootPath(simgear::Dir::current().path());
rootPath.append("pkg_install_archive_type");
simgear::Dir pd(rootPath);
pd.removeChildren();
pkg::RootRef root(new pkg::Root(rootPath, "8.1.2"));
// specify a test dir
root->setHTTPClient(cl);
pkg::CatalogRef c = pkg::Catalog::createFromUrl(root.ptr(), "http://localhost:2000/catalogTest1/catalog.xml");
waitForUpdateComplete(cl, root);
pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.movies");
SG_CHECK_EQUAL(p1->id(), "movies");
pkg::InstallRef ins = p1->install();
SG_VERIFY(ins->isQueued());
waitForUpdateComplete(cl, root);
SG_VERIFY(p1->isInstalled());
SG_VERIFY(p1->existingInstall() == ins);
// verify on disk state
SGPath p(rootPath);
p.append("org.flightgear.test.catalog1");
p.append("Aircraft");
p.append("movies_6789"); // FIXME once archive-dir support is decided
SG_CHECK_EQUAL(p, ins->path());
p.append("movie-list.json");
SG_VERIFY(p.exists());
}
void testDisableDueToVersion(HTTP::Client* cl)
{
global_catalogVersion = 0;
@ -916,6 +958,8 @@ int main(int argc, char* argv[])
testInstallTarPackage(&cl);
testInstallArchiveType(&cl);
testDisableDueToVersion(&cl);
testOfflineMode(&cl);

View File

@ -57,6 +57,10 @@ public:
throw sg_exception("no package download URLs");
}
if (m_owner->package()->properties()->hasChild("archive-type")) {
setArchiveTypeFromExtension(m_owner->package()->properties()->getStringValue("archive-type"));
}
// TODO randomise order of m_urls
m_extractPath = aOwner->path().dir();
@ -196,6 +200,21 @@ protected:
}
private:
void setArchiveTypeFromExtension(const std::string& ext)
{
if (ext.empty())
return;
if (ext == "zip") {
m_archiveType = ZIP;
return;
}
if ((ext == "tar.gz") || (ext == "tgz")) {
m_archiveType = TAR_GZ;
return;
}
}
void extractCurrentFile(unzFile zip, char* buffer, size_t bufferSize)
{
@ -262,11 +281,19 @@ private:
{
const std::string u(url());
const size_t ul(u.length());
if (u.rfind(".zip") == (ul - 4)) {
return extractUnzip();
if (m_archiveType == AUTO_DETECT) {
if (u.rfind(".zip") == (ul - 4)) {
m_archiveType = ZIP;
} else if (u.rfind(".tar.gz") == (ul - 7)) {
m_archiveType = TAR_GZ;
}
// we will fall through to the error case now
}
if (u.rfind(".tar.gz") == (ul - 7)) {
if (m_archiveType == ZIP) {
return extractUnzip();
} else if (m_archiveType == TAR_GZ) {
return extractTar();
}
@ -330,7 +357,14 @@ private:
m_owner->installResult(aReason);
}
enum ArchiveType {
AUTO_DETECT = 0,
ZIP,
TAR_GZ
};
InstallRef m_owner;
ArchiveType m_archiveType = AUTO_DETECT;
string_list m_urls;
SG_MD5_CTX m_md5;
std::string m_buffer;

View File

@ -177,4 +177,17 @@
<file-size-bytes>360</file-size-bytes>
<md5>acf9eb89cf396eb42f8823d9cdf17584</md5>
</package>
<package>
<id>movies</id>
<name>movies files for test catalog aircraft</name>
<revision>10</revision>
<dir>movies_6789</dir>
<!-- url has no file extension, instead we set arcive-type -->
<url>http://localhost:2000/catalogTest1/movies?wierd=foo;bar=thing</url>
<archive-type>zip</archive-type>
<file-size-bytes>232</file-size-bytes>
<md5>e5f89c3f1ed1bdda16174c868f3c7b30</md5>
</package>
</PropertyList>

Binary file not shown.

View File

@ -0,0 +1,3 @@
{
"id": "awesomething"
}