free(buffer);
}
+void createSHA256Info(std::string sha256_info, std::string np)
+{
+ std::ofstream ofs(sha256_info, std::ios::app);
+ int assembly_count = 0;
+ for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
+ std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
+ std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
+ std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
+ std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
+ if (!strcmp(nuget_package.c_str(), np.c_str())) {
+ ofs << assembly << ":" << sha << std::endl;
+ assembly_count++;
+ }
+ }
+ ofs << assembly_count << std::endl;
+ ofs.close();
+}
+
+int compareSHA256Info(std::string sha256_info, std::string np)
+{
+ int compare_count = 0;
+ int assembly_count = 0;
+ std::string sha256_count = "0";
+ for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
+ std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
+ std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
+ std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
+ std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
+ if (!strcmp(nuget_package.c_str(), np.c_str())) {
+ assembly_count++;
+ std::ifstream ifs(sha256_info);
+ std::string get_str;
+ if (ifs.is_open()) {
+ while (getline(ifs, get_str)) {
+ if (!strcmp(get_str.c_str(), (assembly + ":" + sha).c_str())) {
+ compare_count++;
+ }
+ sha256_count = get_str;
+ }
+ ifs.close();
+ }
+ }
+ }
+ if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
+ !strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
+ _INFO("Same nuget : %s", np.c_str());
+ return 1;
+ }
+ return 0;
+}
+
int copyNCreateSymlink(std::string tac_version_dir, std::string np, bool is_create_tac_dir)
{
- uid_t uid = 0;
- if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
+ uid_t g_uid = 0;
+ gid_t g_gid = 0;
+ if (pkgmgr_installer_info_get_target_uid(&g_uid) < 0) {
_ERR("Failed to get UID");
return -1;
}
}
}
bf::create_symlink(concatPath(tac_version_dir, assembly), concatPath(tac_dir, assembly));
- if (lchown(concatPath(tac_dir, assembly).c_str(), uid, 0)) {
+ if (lchown(concatPath(tac_dir, assembly).c_str(), g_uid, g_gid)) {
_ERR("Failed to change owner of: %s", concatPath(tac_dir, assembly).c_str());
return -1;
}
return 0;
}
createDirectories.push_back(tac_version_dir);
- std::ofstream ofs(sha256_info, std::ios::app);
- int assembly_count = 0;
- for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
- std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
- std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
- std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
- std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
- if (!strcmp(nuget_package.c_str(), np.c_str())) {
- ofs << assembly << ":" << sha << std::endl;
- assembly_count++;
- }
+ if (!bf::is_symlink(sha256_info)) {
+ createSHA256Info(sha256_info, np);
+ } else {
+ _ERR("Failed to create sha256_info. Symbolic link is detected");
+ return -1;
}
- ofs << assembly_count << std::endl;
- ofs.close();
if (copyNCreateSymlink(tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
- std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
+
+ char *sql = sqlite3_mprintf(
+ "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
+ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
dbInsert(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
} else {
_INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
- int compare_count = 0;
- int assembly_count = 0;
- std::string sha256_count = "0";
- for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
- std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
- std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
- std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
- std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
- if (!strcmp(nuget_package.c_str(), np.c_str())) {
- assembly_count++;
- std::ifstream ifs(sha256_info);
- std::string get_str;
- if (ifs.is_open()) {
- while (getline(ifs, get_str)) {
- if (!strcmp(get_str.c_str(), (assembly + ":" + sha).c_str())) {
- compare_count++;
- }
- sha256_count = get_str;
- }
- ifs.close();
+ if (!bf::is_symlink(sha256_info)) {
+ if (compareSHA256Info(sha256_info, np)) {
+ if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
+ _ERR("Failed to create symlink");
+ return -1;
}
+
+ char *sql = sqlite3_mprintf(
+ "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
+ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
+ dbInsert(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+ } else {
+ _INFO("Different nuget : %s", np.c_str());
}
- }
- if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
- !strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
- _INFO("Same nuget : %s", np.c_str());
- if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
- _ERR("Failed to create symlink");
- return -1;
- }
- std::string sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
- dbInsert(tac_db, TAC_APP_LIST_DB, sql);
} else {
- _INFO("Different nuget : %s", np.c_str());
+ _ERR("Failed to create sha256_info. Symbolic link is detected");
+ return -1;
}
}
if (!bf::exists(sha256_info)) {
{
for (auto& unp : updateTac) {
int count = -1;
- std::string sql = "SELECT COUNT(NUGET) FROM TAC WHERE NUGET = '" + unp + "';";
- int ret = sqlite3_exec(sqlite, sql.c_str(), sqliteCb, &count, NULL);
+ char *sql = sqlite3_mprintf("SELECT COUNT(NUGET) FROM TAC WHERE NUGET = %Q;", unp.c_str());
+ int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
if (ret != SQLITE_OK) {
_ERR("Sqlite select error");
+ sqlite3_free(sql);
return -1;
}
if (count == 0) {
std::string tac_version_dir_backup = tac_version_dir_prev + ".bck";
if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
_ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
+ sqlite3_free(sql);
return -1;
}
if (!removeAll(tac_version_dir_prev)) {
_ERR("Failed to remove of %s", tac_version_dir_prev.c_str());
+ sqlite3_free(sql);
return -1;
}
}
+ sqlite3_free(sql);
}
return 0;
}
return 0;
}
- std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
if (tacDB.empty()) {
- sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
dbDelete(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
if (updateTacDB(tac_db) < 0) {
return -1;
}
return 0;
}
createDirectories.push_back(tac_version_dir);
- std::ofstream ofs(sha256_info, std::ios::app);
- int assembly_count = 0;
- for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
- std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
- std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
- std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
- std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
- if (!strcmp(nuget_package.c_str(), np.c_str())) {
- ofs << assembly << ":" << sha << std::endl;
- assembly_count++;
- }
+ if (!bf::is_symlink(sha256_info)) {
+ createSHA256Info(sha256_info, np);
+ } else {
+ _ERR("Failed to create sha256_info. Symbolic link is detected");
+ return -1;
}
- ofs << assembly_count << std::endl;
- ofs.close();
+
if (copyNCreateSymlink(tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
int count = -1;
- sql = "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = '" + std::string(pkgId) + "' AND NAME = '" + tac_name + "';";
- int ret = sqlite3_exec(tac_db, sql.c_str(), sqliteCb, &count, NULL);
+ sql = sqlite3_mprintf(
+ "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
+ int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
if (ret != SQLITE_OK) {
_ERR("Sqlite select error");
+ sqlite3_free(sql);
return -1;
}
if (count == 1) {
- sql = "UPDATE TAC SET NAME = '" + tac_name + "', VERSION = '" + tac_version + "', NUGET = '" + np + "' WHERE PKGID = '" + std::string(pkgId) + "' AND NAME = '" + tac_name + "';";
+ sql = sqlite3_mprintf(
+ "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
+ tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
} else if (count == 0) {
- sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
+ sql = sqlite3_mprintf(
+ "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
+ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
dbInsert(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
}
} else {
_INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
- int compare_count = 0;
- int assembly_count = 0;
- std::string sha256_count = "0";
- for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
- std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
- std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
- std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
- std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
- if (!strcmp(nuget_package.c_str(), np.c_str())) {
- assembly_count++;
- std::ifstream ifs(sha256_info);
- std::string get_str;
- if (ifs.is_open()) {
- while (getline(ifs, get_str)) {
- if (!strcmp(get_str.c_str(), (assembly + ":" + sha).c_str())) {
- compare_count++;
- }
- sha256_count = get_str;
- }
- ifs.close();
+ if (!bf::is_symlink(sha256_info)) {
+ if (compareSHA256Info(sha256_info, np)) {
+ if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
+ _ERR("Failed to create symlink");
+ return -1;
}
- }
- }
- if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
- !strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
- _INFO("Same nuget : %s", np.c_str());
- if (copyNCreateSymlink(tac_version_dir, np, false) < 0) {
- _ERR("Failed to create symlink");
- return -1;
- }
-
- int count = -1;
- std::string sql = "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = '" + std::string(pkgId) + "' AND NAME = '" + tac_name + "';";
- int ret = sqlite3_exec(tac_db, sql.c_str(), sqliteCb, &count, NULL);
- if (ret != SQLITE_OK) {
- _ERR("Sqlite select error");
- return -1;
- }
- if (count == 1) {
- sql = "UPDATE TAC SET NAME = '" + tac_name + "', VERSION = '" + tac_version + "', NUGET = '" + np + "' WHERE PKGID = '" + std::string(pkgId) + "' AND NAME = '" + tac_name + "';";
- dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
- } else if (count == 0) {
- sql = "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES ('" + std::string(pkgId) + "', '" + np + "', '" + tac_name + "', '" + tac_version + "');";
- dbInsert(tac_db, TAC_APP_LIST_DB, sql);
+ int count = -1;
+ char *sql = sqlite3_mprintf(
+ "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
+ int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
+ if (ret != SQLITE_OK) {
+ _ERR("Sqlite select error");
+ sqlite3_free(sql);
+ return -1;
+ }
+ if (count == 1) {
+ sql = sqlite3_mprintf(
+ "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
+ tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
+ dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+ } else if (count == 0) {
+ sql = sqlite3_mprintf(
+ "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
+ "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
+ dbInsert(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+ }
+ } else {
+ _INFO("Different nuget : %s", np.c_str());
}
} else {
- _INFO("Different nuget : %s", np.c_str());
+ _ERR("Failed to create sha256_info. Symbolic link is detected");
+ return -1;
}
}
if (!bf::exists(sha256_info)) {
}
}
if (!isExits) {
- std::string sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "' AND NUGET = '" + unp + "';";
+ char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str());
dbDelete(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
}
}
if (updateTacDB(tac_db) < 0) {
return 0;
}
- std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
- sql = "DELETE FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
dbDelete(tac_db, TAC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
if (updateTacDB(tac_db) < 0) {
return -1;