75 lines
2.9 KiB
C
75 lines
2.9 KiB
C
#pragma once
|
|
#include "database.h"
|
|
#include "package.h"
|
|
|
|
#include <sqlite3.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <sys/types.h>
|
|
|
|
#define HASH_LEN 32
|
|
|
|
enum lm_query_index {
|
|
QUERY_CREATE_TABLE = 0,
|
|
QUERY_INSERT_SINGLE = 1,
|
|
QUERY_SELECT_SINGLE_1 = 2,
|
|
QUERY_SELECT_SINGLE_2 = 3,
|
|
QUERY_DELETE_SINGLE = 4,
|
|
QUERY_SELECT_ALL = 5,
|
|
};
|
|
|
|
enum lm_columns {
|
|
COLUMN_NAME = 1,
|
|
COLUMN_VERSION = 2,
|
|
COLUMN_DESC = 3,
|
|
COLUMN_SIZE = 4,
|
|
COLUMN_DEPENDS = 5,
|
|
};
|
|
|
|
extern char *queries[];
|
|
|
|
typedef lm_pkg_data_t lm_entry_t;
|
|
|
|
typedef struct lm_database {
|
|
sqlite3 *sql;
|
|
sqlite3_stmt *st;
|
|
FILE *filesp;
|
|
char *dir;
|
|
} lm_database_t;
|
|
|
|
void lm_entry_init(lm_entry_t *entry);
|
|
void lm_entry_free(lm_entry_t *entry);
|
|
|
|
lm_database_t *lm_database_new(char *path);
|
|
void lm_database_free(lm_database_t *db);
|
|
bool lm_database_step_all(sqlite3_stmt *st);
|
|
|
|
bool lm_database_entry_find(
|
|
lm_database_t *db, lm_entry_t *out, char *name, char *version); // finds a entry by its name, entry stored in *pkg
|
|
bool lm_database_entry_next(lm_database_t *db, lm_entry_t *entry); // gets the next entry in the database
|
|
bool lm_database_entry_add(lm_database_t *db, lm_entry_t *entry); // adds a entry to the database
|
|
bool lm_database_entry_del(lm_database_t *db, lm_entry_t *entry); // delete a entry from the database
|
|
void lm_database_entry_next_free(
|
|
lm_database_t *db, lm_entry_t *entry); // frees resources used for lm_database_entry_next
|
|
|
|
ssize_t lm_database_files_count(
|
|
lm_database_t *db, lm_entry_t *entry); // returns the count of files associated with a entry
|
|
bool lm_database_files_contains(
|
|
lm_database_t *db, lm_entry_t *entry, char *path); // check if a entry contains the given file
|
|
bool lm_database_files_matches(
|
|
lm_database_t *db, char *path, char *hash); // checks if the given file matches with the given hash
|
|
bool lm_database_files_iskeep(lm_database_t *db, char *path); // checks if the given file is marked as keep
|
|
bool lm_database_files_next(
|
|
lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep); // gets the next file of the entry
|
|
bool lm_database_files_add(
|
|
lm_database_t *db, lm_entry_t *entry, char *path, char *hash); // adds a file to the files database
|
|
bool lm_database_files_del(
|
|
lm_database_t *db, lm_entry_t *entry); // dels files belonging to an entry that is not set as KEEP
|
|
bool lm_database_files_del_all(lm_database_t *db, lm_entry_t *entry); // dels all files of belonging to an entry
|
|
void lm_database_files_next_free(lm_database_t *db, lm_entry_t *entry, char **path, char **hash,
|
|
bool *keep); // frees resources used for lm_database_files_next
|
|
|
|
bool lm_database_changes_update(lm_database_t *db, lm_entry_t *entry, char *file);
|
|
char *lm_database_changes_get(lm_database_t *db, lm_entry_t *entry);
|
|
bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry);
|