update: make the package changes file read-only
This commit is contained in:
parent
2e918b55ee
commit
b8d2d69752
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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 ""
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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){
|
||||
|
Loading…
Reference in New Issue
Block a user