fix: install getline issues

This commit is contained in:
ngn 2024-07-06 04:15:38 +03:00
parent 3a6f1c06c0
commit 93eb7bb8b4
3 changed files with 33 additions and 11 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-06 03:45+0300\n"
"POT-Creation-Date: 2024-07-06 04:13+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"

View File

@ -55,40 +55,60 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
return false; // error set by function
if(!lm_package_is_same(&temp, pkg)){
pdebug(__func__, "DATA file does not match with stored %s data", pkg->name);
lm_error_set(LM_ERR_PkgDataNotMatch);
return false;
}
if(!lm_database_changes_update(ctx->db, pkg, changes_file)){
char *suberr = lm_strerror_dup();
pdebug(__func__, "failed to update changes file for %s: %s", pkg->name, suberr);
lm_error_set(LM_ERR_PkgChangesUpdateFail, suberr);
return false;
}
char *line = NULL, *hash = NULL, *file = NULL;
size_t line_len = 0;
ssize_t line_len = 0;
FILE *hashes = NULL;
bool ret = false;
if((hashes = fopen(hashes_file, "r")) == NULL){
pdebug(__func__, "failed to open hash file for %s", pkg->name);
lm_error_set(LM_ERR_PkgHashesOpenFail);
return false;
}
while((line_len = getline(&line, 0, hashes)) > 0){
while((line_len = getline(&line, (size_t*)&line_len, hashes)) > 0){
if(NULL == line)
goto next;
if(HASH_LEN+1 >= line_len)
continue;
goto next;
line[HASH_LEN] = 0;
hash = line;
file = line+HASH_LEN+1;
file = line+HASH_LEN+2;
file[strlen(file)-1] = 0;
if(file[0] == '.')
file++;
pdebug(__func__, "(%lu) %s => %s", line_len, file, hash);
if(!lm_database_files_add(ctx->db, pkg, file, hash))
return false; // error set by function
goto end;
next:
free(line);
line = NULL;
line_len = 0;
}
ret = true;
end:
free(line);
if(NULL != hashes)
fclose(hashes);

View File

@ -34,7 +34,7 @@ char *queries[] = {
" path TEXT PRIMARY KEY NOT NULL," \
" hash TEXT NOT NULL," \
" keep INT NOT NULL," \
" package TEXT NOT NULL);"
" package TEXT NOT NULL);",
// QUERY_INSERT_FILE_SINGLE
"INSERT INTO files VALUES (?, ?, ?, ?)",
@ -77,27 +77,29 @@ lm_database_t *lm_database_new(char *path){
join(filesdb, path, "files.db");
if(sqlite3_open(packagesdb, &db->packages_db)){
pdebug(__func__, "(%s) failed to open databse: %s", path, sqlite3_errmsg(db->packages_db));
pdebug(__func__, "(%s) failed to open databse: %s", packagesdb, sqlite3_errmsg(db->packages_db));
lm_error_set(LM_ERR_DbSqlOpenFail);
return NULL;
}
if(sqlite3_open(filesdb, &db->files_db)){
pdebug(__func__, "(%s) failed to open databse: %s", path, sqlite3_errmsg(db->files_db));
pdebug(__func__, "(%s) failed to open databse: %s", filesdb, sqlite3_errmsg(db->files_db));
lm_error_set(LM_ERR_DbSqlOpenFail);
return NULL;
}
if(sqlite3_exec(db->packages_db, queries[QUERY_CREATE_PACKAGE_TABLE], NULL, 0, &err) != SQLITE_OK){
pdebug(__func__, "(%s) failed to create packages table: %s", path, err);
pdebug(__func__, "(%s) failed to create packages table: %s", packagesdb, err);
lm_error_set(LM_ERR_DbSqlCreateFail);
sqlite3_free(err);
db->packages_db = NULL;
}
if(sqlite3_exec(db->files_db, queries[QUERY_CREATE_FILE_TABLE], NULL, 0, &err) != SQLITE_OK){
pdebug(__func__, "(%s) failed to create files table: %s", path, err);
pdebug(__func__, "(%s) failed to create files table: %s", filesdb, err);
lm_error_set(LM_ERR_DbSqlCreateFail);
sqlite3_free(err);
db->files_db = NULL;
}
db->dir = strdup(path);