diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx
index 6a4446c0..f61763c2 100644
--- a/simgear/package/CatalogTest.cxx
+++ b/simgear/package/CatalogTest.cxx
@@ -92,6 +92,11 @@ public:
path = ss.str();
}
}
+
+ // return zip data for this computed URL
+ if (path.find("/catalogTest1/movies") == 0) {
+ path = "/catalogTest1/movies-data.zip";
+ }
localPath.append(path);
@@ -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;
@@ -915,7 +957,9 @@ int main(int argc, char* argv[])
testRefreshCatalog(&cl);
testInstallTarPackage(&cl);
-
+
+ testInstallArchiveType(&cl);
+
testDisableDueToVersion(&cl);
testOfflineMode(&cl);
diff --git a/simgear/package/Install.cxx b/simgear/package/Install.cxx
index 7e22f0f2..96cd11e6 100644
--- a/simgear/package/Install.cxx
+++ b/simgear/package/Install.cxx
@@ -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,7 +200,22 @@ 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)
{
unz_file_info fileInfo;
@@ -262,14 +281,22 @@ 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();
}
-
+
SG_LOG(SG_IO, SG_WARN, "unsupported archive format:" << u);
return false;
}
@@ -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;
diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml
index 26fb7025..1b8b7b59 100644
--- a/simgear/package/catalogTest1/catalog.xml
+++ b/simgear/package/catalogTest1/catalog.xml
@@ -177,4 +177,17 @@
360
acf9eb89cf396eb42f8823d9cdf17584
+
+
+
+ movies
+ movies files for test catalog aircraft
+ 10
+ movies_6789
+
+ http://localhost:2000/catalogTest1/movies?wierd=foo;bar=thing
+ zip
+ 232
+ e5f89c3f1ed1bdda16174c868f3c7b30
+
diff --git a/simgear/package/catalogTest1/movies-data.zip b/simgear/package/catalogTest1/movies-data.zip
new file mode 100644
index 00000000..695ec1e7
Binary files /dev/null and b/simgear/package/catalogTest1/movies-data.zip differ
diff --git a/simgear/package/catalogTest1/movies_6789/movie-list.json b/simgear/package/catalogTest1/movies_6789/movie-list.json
new file mode 100644
index 00000000..13be6b27
--- /dev/null
+++ b/simgear/package/catalogTest1/movies_6789/movie-list.json
@@ -0,0 +1,3 @@
+{
+ "id": "awesomething"
+}
\ No newline at end of file