// run migration if old database is present
auto sv = this->getSchemaVersion();
- if (sv < SchemaVersion::NOT_EXIST || sv > SchemaVersion::LATEST) {
- ERROR("Database corrupted! invalid db version returned! : " << sv);
- this->resetDatabase();
- return;
- } else if (sv == SchemaVersion::LATEST) {
+ switch (sv) {
+ case SchemaVersion::LATEST:
DEBUG("Database version is latest");
- return;
- }
+ break;
- if (sv == SchemaVersion::NOT_EXIST) {
+ case SchemaVersion::NOT_EXIST:
INFO("Database initializing!");
this->resetDatabase();
- } else if (sv < SchemaVersion::LATEST) {
- INFO("Database migration! from[" << sv <<
- "] to[" << SchemaVersion::LATEST << "]");
+ break;
- for (int vi = sv; vi < SchemaVersion::LATEST; ++vi)
- this->m_conn.exec(this->getMigrationScript(vi).c_str());
+ default:
+ if (sv < SchemaVersion::NOT_EXIST || sv > SchemaVersion::LATEST) {
+ ERROR("Database corrupted! invalid db version returned! : " << sv);
+ this->resetDatabase();
+ } else {
+ INFO("Database migration! from[" << sv <<
+ "] to[" << SchemaVersion::LATEST << "]");
- this->setSchemaVersion(SchemaVersion::LATEST);
+ for (int vi = sv; vi < SchemaVersion::LATEST; ++vi)
+ this->m_conn.exec(this->getMigrationScript(vi).c_str());
+
+ this->setSchemaVersion(SchemaVersion::LATEST);
+ }
+ break;
}
this->m_conn.exec("VACUUM;");
RawBuffer CsLogic::scanApp(const CsContext &context, const std::string &pkgPath)
{
- FilePtr fileptr;
- try {
- fileptr = File::create(pkgPath);
- } catch (const Exception &e) {
- if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST)
- WARN("Package path of file[" << pkgPath << "] doesn't exist or perm denied.");
- else if (e.error() == CSR_ERROR_FILE_SYSTEM)
- WARN("Package path of file[" << pkgPath << "] type isn't regular file or dir.");
- else
- throw;
- }
+ auto fileptr = File::create(pkgPath);
+ if (!fileptr)
+ ThrowExc(CSR_ERROR_SERVER, "fileptr shouldn't be empty because didn't check modified");
if (!fileptr->isInApp())
ThrowExc(CSR_ERROR_SERVER, "fileptr should be in app.");