90 lines
3.2 KiB
C
90 lines
3.2 KiB
C
#pragma once
|
|
#include "database.h"
|
|
#include "package.h"
|
|
|
|
#include <sqlite3.h>
|
|
#include <stdbool.h>
|
|
#include <sys/types.h>
|
|
|
|
#define HASH_LEN 32
|
|
|
|
enum lm_query_index {
|
|
QUERY_CREATE_ENTRY_TABLE = 0,
|
|
QUERY_INSERT_ENTRY_SINGLE = 1,
|
|
QUERY_SELECT_ENTRY_SINGLE_1 = 2,
|
|
QUERY_SELECT_ENTRY_SINGLE_2 = 3,
|
|
QUERY_DELETE_ENTRY_SINGLE = 4,
|
|
QUERY_SELECT_ENTRY_ALL = 5,
|
|
|
|
QUERY_CREATE_FILE_TABLE = 6,
|
|
QUERY_INSERT_FILE_SINGLE = 7,
|
|
QUERY_DELETE_FILE_ALL = 8,
|
|
QUERY_DELETE_FILE_SINGLE = 9,
|
|
QUERY_SELECT_FILE_ALL = 10,
|
|
QUERY_SELECT_FILE_SINGLE = 11,
|
|
QUERY_UPDATE_FILE_1 = 12,
|
|
QUERY_UPDATE_FILE_2 = 13,
|
|
};
|
|
|
|
enum lm_columns {
|
|
FILES_COLUMN_PATH = 1,
|
|
FILES_COLUMN_HASH = 2,
|
|
FILES_COLUMN_KEEP = 3,
|
|
FILES_COLUMN_ENTRY = 4,
|
|
|
|
ENTRIES_COLUMN_NAME = 1,
|
|
ENTRIES_COLUMN_VERSION = 2,
|
|
ENTRIES_COLUMN_DESC = 3,
|
|
ENTRIES_COLUMN_SIZE = 4,
|
|
ENTRIES_COLUMN_DEPENDS = 5,
|
|
};
|
|
|
|
extern char *queries[];
|
|
|
|
typedef lm_pkg_data_t lm_entry_t;
|
|
|
|
typedef struct lm_database {
|
|
sqlite3 *entries_db;
|
|
sqlite3_stmt *entries_st;
|
|
|
|
sqlite3 *files_db;
|
|
sqlite3_stmt *files_st;
|
|
|
|
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 all files of belonging to a entry
|
|
bool lm_database_files_del_single(lm_database_t *db, char *path);
|
|
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);
|