commit e3a82fbd86ae4604e9d6ab9af337af3ca71c33a4
parent 07fc0b0f0fae6b256a0eb95da8365acce4ac4f53
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 5 Jun 2016 20:46:02 -0400
fix registration of scripts embedded in non-script packages
Diffstat:
8 files changed, 62 insertions(+), 22 deletions(-)
diff --git a/src/registry.cpp b/src/registry.cpp
@@ -58,9 +58,9 @@ Registry::Registry(const Path &path)
// file queries
m_getFiles = m_db.prepare("SELECT path FROM files WHERE entry = ?");
m_getMainFiles = m_db.prepare(
- "SELECT path FROM files WHERE main = 1 AND entry = ?"
+ "SELECT path, type FROM files WHERE main = 1 AND entry = ?"
);
- m_insertFile = m_db.prepare("INSERT INTO files VALUES(NULL, ?, ?, ?)");
+ m_insertFile = m_db.prepare("INSERT INTO files VALUES(NULL, ?, ?, ?, ?)");
m_clearFiles = m_db.prepare(
"DELETE FROM files WHERE entry = ("
" SELECT id FROM entries WHERE remote = ? AND category = ? AND package = ?"
@@ -96,14 +96,17 @@ void Registry::migrate()
" id INTEGER PRIMARY KEY,"
" entry INTEGER NOT NULL,"
" path TEXT UNIQUE NOT NULL,"
- " main INTEGER DEFAULT 0,"
+ " main INTEGER NOT NULL,"
+ " type INTEGER,"
" FOREIGN KEY(entry) REFERENCES entries(id)"
");"
);
break;
case 1:
- m_db.exec("ALTER TABLE entries ADD COLUMN pinned INTEGER DEFAULT 0;");
+ m_db.exec("ALTER TABLE entries ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0;");
case 2:
+ m_db.exec("ALTER TABLE files ADD COLUMN type INTEGER NOT NULL DEFAULT 0;");
+ case 3:
// current schema version
break;
default:
@@ -111,7 +114,7 @@ void Registry::migrate()
"The package registry was created by a newer version of ReaPack");
}
- m_db.exec("PRAGMA user_version = 2");
+ m_db.exec("PRAGMA user_version = 3");
m_db.commit();
}
@@ -161,6 +164,7 @@ auto Registry::push(const Version *ver, vector<Path> *conflicts) -> Entry
m_insertFile->bind(1, entryId);
m_insertFile->bind(2, path.join('/'));
m_insertFile->bind(3, src->isMain());
+ m_insertFile->bind(4, src->typeOverride());
try {
m_insertFile->exec();
@@ -268,16 +272,22 @@ set<Path> Registry::getFiles(const Entry &entry) const
return list;
}
-vector<string> Registry::getMainFiles(const Entry &entry) const
+auto Registry::getMainFiles(const Entry &entry) const -> vector<File>
{
if(!entry)
return {};
- vector<string> files;
+ vector<File> files;
m_getMainFiles->bind(1, entry.id);
m_getMainFiles->exec([&] {
- files.push_back(m_getMainFiles->stringColumn(0));
+ File file{m_getMainFiles->stringColumn(0)};
+ file.type = static_cast<Package::Type>(m_getMainFiles->intColumn(1));
+
+ if(!file.type) // < v1.0rc2
+ file.type = entry.type;
+
+ files.push_back(file);
return true;
});
diff --git a/src/registry.hpp b/src/registry.hpp
@@ -44,12 +44,17 @@ public:
operator bool() const { return id != 0; }
};
+ struct File {
+ Path path;
+ Package::Type type;
+ };
+
Registry(const Path &path = {});
Entry getEntry(const Package *) const;
std::vector<Entry> getEntries(const std::string &) const;
std::set<Path> getFiles(const Entry &) const;
- std::vector<std::string> getMainFiles(const Entry &) const;
+ std::vector<File> getMainFiles(const Entry &) const;
Entry push(const Version *, std::vector<Path> *conflicts = nullptr);
void setPinned(const Entry &, bool pinned);
void forget(const Entry &);
diff --git a/src/source.cpp b/src/source.cpp
@@ -35,14 +35,23 @@ const Package *Source::package() const
return m_version ? m_version->package() : nullptr;
}
+Package::Type Source::type() const
+{
+ if(m_type)
+ return m_type;
+ else if(const Package *pkg = package())
+ return pkg->type();
+ else
+ return Package::UnknownType;
+}
+
+
const string &Source::file() const
{
if(!m_file.empty())
return m_file;
- const Package *pkg = package();
-
- if(pkg)
+ if(const Package *pkg = package())
return pkg->name();
else
throw reapack_error("empty file name and no package");
@@ -69,8 +78,7 @@ Path Source::targetPath() const
throw reapack_error("category or index is unset");
Path path;
-
- const Package::Type type = m_type ? m_type : pkg->type();
+ const auto type = this->type();
// select the target directory
switch(type) {
diff --git a/src/source.hpp b/src/source.hpp
@@ -35,6 +35,7 @@ public:
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 setMain(bool main) { m_main = main; }
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -365,7 +365,7 @@ bool Transaction::runTasks()
void Transaction::registerInHost(const bool add, const Registry::Entry &entry)
{
// don't actually do anything until commit() – which will calls registerQueued
- for(const string &mainFile : m_registry->getMainFiles(entry))
+ for(const Registry::File &mainFile : m_registry->getMainFiles(entry))
m_regQueue.push({add, entry, mainFile});
}
@@ -380,7 +380,7 @@ void Transaction::registerQueued()
return;
}
- switch(reg.entry.type) {
+ switch(reg.file.type) {
case Package::ScriptType:
registerScript(reg);
break;
@@ -408,11 +408,11 @@ void Transaction::registerScript(const HostTicket ®)
else
section = MainSection;
- const string &fullPath = Path::prefixRoot(reg.file).join();
+ const string &fullPath = Path::prefixRoot(reg.file.path).join();
const bool isLast = m_regQueue.size() == 1;
if(!AddRemoveReaScript(reg.add, section, fullPath.c_str(), isLast) && reg.add)
- addError("Script could not be registered in REAPER.", reg.file);
+ addError("This script could not be registered in REAPER.", reg.file.path.join());
}
void Transaction::inhibit(const Remote &remote)
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -36,7 +36,7 @@ struct InstallOpts;
typedef std::shared_ptr<const Index> IndexPtr;
-struct HostTicket { bool add; Registry::Entry entry; std::string file; };
+struct HostTicket { bool add; Registry::Entry entry; Registry::File file; };
class Transaction {
public:
diff --git a/test/registry.cpp b/test/registry.cpp
@@ -169,16 +169,20 @@ TEST_CASE("get main files", M) {
Source *main1 = new Source({}, "url", ver);
main1->setMain(true);
+ main1->setTypeOverride(Package::EffectType);
ver->addSource(main1);
- Source *main2 = new Source({}, "url", ver); // duplicate file
+ Source *main2 = new Source({}, "url", ver); // duplicate file ignored
main2->setMain(true);
+ main2->setTypeOverride(Package::EffectType);
ver->addSource(main2);
const Registry::Entry &entry = reg.push(ver);
- const vector<string> expected{main1->targetPath().join('/')};
- REQUIRE(reg.getMainFiles(entry) == expected);
+ const vector<Registry::File> ¤t = reg.getMainFiles(entry);
+ REQUIRE(current.size() == 1);
+ REQUIRE(current[0].path == main1->targetPath());
+ REQUIRE(current[0].type == Package::EffectType);
}
TEST_CASE("pin registry entry", M) {
diff --git a/test/source.cpp b/test/source.cpp
@@ -23,12 +23,24 @@ TEST_CASE("source platform", M) {
TEST_CASE("source type override", M) {
Source src({}, "url");
+ REQUIRE(src.type() == Package::UnknownType);
REQUIRE(src.typeOverride() == Package::UnknownType);
src.setTypeOverride(Package::ScriptType);
+ REQUIRE(src.type() == Package::ScriptType);
REQUIRE(src.typeOverride() == Package::ScriptType);
}
+TEST_CASE("source type from package", M) {
+ Package pack(Package::EffectType, "package name");
+ Version ver("1.0", &pack);
+ Source src({}, "url", &ver);
+
+ REQUIRE(src.type() == Package::EffectType);
+ src.setTypeOverride(Package::ScriptType);
+ REQUIRE(src.type() == Package::ScriptType);
+}
+
TEST_CASE("empty file name and no package", M) {
const Source source({}, "url");