update: make the package changes file read-only

This commit is contained in:
ngn 2024-07-19 19:23:48 +03:00
parent 2e918b55ee
commit b8d2d69752
8 changed files with 41 additions and 14 deletions

View File

@ -140,6 +140,8 @@ typedef enum lm_error {
LM_ERR_FileHashNoMatch = 132,
LM_ERR_InfoNotLoaded = 133,
LM_ERR_NoPools = 134,
LM_ERR_DbChangesNotExists = 135,
LM_ERR_DbChangesChmodFail = 136,
} lm_error_t;
typedef struct lm_error_desc {

View File

@ -21,7 +21,7 @@ bool lm_package_downloaded(lm_pkg_t *pkg);
bool lm_package_depend_add(lm_pkg_t *pkg, char *depend);
size_t lm_package_depend_count(lm_pkg_t *pkg);
size_t lm_package_depend_strlen(lm_pkg_t *pkg);
bool lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer);
char *lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer);
bool lm_package_depend_fromstr(lm_pkg_t *pkg, char *buffer);
void lm_package_depend_free(lm_pkg_t *pkg);
bool lm_package_depends(lm_pkg_t *pkg, char *dep);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-18 23:48+0300\n"
"POT-Creation-Date: 2024-07-19 19:22+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -591,3 +591,11 @@ msgstr "URL hostname is too large"
#: src/error.c:159
msgid "pool list is empty"
msgstr ""
#: src/error.c:160
msgid "package changes file not found in the database"
msgstr ""
#: src/error.c:161
msgid "failed to change mod of the changes file"
msgstr ""

View File

@ -72,11 +72,11 @@ bool lm_ctx_database_next_free(lm_ctx_t *ctx, lm_pkg_t *pkg){
char *lm_ctx_database_changes(lm_ctx_t *ctx, lm_pkg_t *pkg){
if(NULL == ctx || NULL == pkg){
lm_error_set(LM_ERR_ArgNULL);
return false;
return NULL;
}
if(!lm_ctx_database_init(ctx))
return false; // error set by function
return NULL; // error set by function
return lm_database_changes_get(ctx->db, pkg);
}

View File

@ -20,7 +20,15 @@ bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file){
char changes_path[strlen(db->dir)+sizeof(changes_file)];
join(changes_path, db->dir, changes_file);
return copy_file(changes_path, file);
if(!copy_file(changes_path, file))
return false;
if(chmod(changes_path, 0444) < 0){
lm_error_set(LM_ERR_DbChangesChmodFail);
return false;
}
return true;
}
bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg){
@ -51,6 +59,7 @@ char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg){
join(changes_path, db->dir, changes_file);
if(!exists(changes_path)){
lm_error_set(LM_ERR_DbChangesNotExists);
free(changes_path);
return NULL;
}

View File

@ -101,7 +101,7 @@ bool lm_database_package_find(lm_database_t *db, lm_pkg_t *pkg, char *name, char
// error is set by the function
goto end;
}
ret = true;
end:
if(NULL != db->packages_st){
@ -151,13 +151,13 @@ bool lm_database_package_next(lm_database_t *db, lm_pkg_t *pkg){
if(NULL != db->packages_st)
lm_package_free(pkg);
else if(NULL == db->packages_st &&
else if(NULL == db->packages_st &&
sqlite3_prepare(db->packages_db, queries[QUERY_SELECT_PACKAGE_ALL], strlen(queries[QUERY_SELECT_PACKAGE_ALL]), &db->packages_st, NULL) != SQLITE_OK){
pdebug(__func__, "failed to prepare statement for selecting all: %s", sqlite3_errmsg(db->packages_db));
lm_error_set(LM_ERR_DbSqlPrepareFail);
return false;
}
lm_package_init(pkg);
if(sqlite3_step(db->packages_st) != SQLITE_ROW){
@ -191,7 +191,7 @@ void lm_database_package_next_free(lm_database_t *db, lm_pkg_t *pkg){
sqlite3_finalize(db->packages_st);
db->packages_st = NULL;
}
if(NULL != pkg)
lm_package_free(pkg);
}

View File

@ -157,6 +157,8 @@ void lm_error_set(lm_error_t code, ...) {
{.code = LM_ERR_FileHashNoMatch, .desc = _("file hash does not match for %s") },
{.code = LM_ERR_InfoNotLoaded, .desc = _("pool info is not loaded") },
{.code = LM_ERR_NoPools, .desc = _("pool list is empty") },
{.code = LM_ERR_DbChangesNotExists, .desc = _("package changes file not found in the database") },
{.code = LM_ERR_DbChangesChmodFail, .desc = _("failed to change mod of the changes file") },
};
char *fmt = NULL;

View File

@ -69,15 +69,21 @@ size_t lm_package_depend_strlen(lm_pkg_t *pkg){
return len;
}
bool lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
if(NULL == buffer || NULL == pkg){
char *lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
if(NULL == pkg){
lm_error_set(LM_ERR_ArgNULL);
return false;
return NULL;
}
if(NULL == buffer){
size_t buflen = lm_package_depend_strlen(pkg)+1;
buffer = malloc(buflen);
bzero(buffer, buflen);
}
if(NULL == pkg->depends){
buffer[0] = 0;
return true;
return buffer;
}
size_t bufsz = 0, depsz = 0;
@ -97,7 +103,7 @@ bool lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
}
buffer[bufsz] = 0;
return true;
return buffer;
}
bool lm_package_depend_fromstr(lm_pkg_t *pkg, char *buffer){