The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
repo.c File Reference

librat: the repository. More...

#include "internal.h"
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

Macros

#define REPOS_FILE   "etc/rat/repos.conf"
#define INDEX_FILE   RAT_DB_DIR "/index.conf"
#define SIG_FILE   RAT_DB_DIR "/index.conf.sig"
#define SEQUENCE_FILE   RAT_DB_DIR "/sequence"
#define CACHE_DIR   RAT_DB_DIR "/cache"
#define INDEX_MAX   (8u * 1024 * 1024)
 the largest index and signature that rat downloads
#define SIGNATURE_MAX   1024u

Functions

int rat_index_load (rat_t *rat, rat_index_t *index, rat_error_t *err)
 read the index that rat_update kept, and check its signature again.
int rat_update (rat_t *rat, rat_progress_t progress, void *context, rat_update_t *result_out, rat_error_t *err)
 get the index of the repository (the url for this architecture in <root>/etc/rat/repos.conf) and its signature, check them, and keep them.
int rat_install_name (rat_t *rat, const char *name, unsigned flags, rat_note_t note, rat_progress_t progress, void *context, rat_error_t *err)
 install or upgrade a package of the index: download it into the cache, check its size and SHA-256 against the index, then install it as rat_install_file does.
int rat_upgradable (rat_t *rat, const rat_index_t *index, rat_upgradable_t **items_out, int *count_out, rat_error_t *err)
 the installed packages that the index has in a newer version, sorted by name.
void rat_upgradables_free (rat_upgradable_t *items, int count)
 release an array from rat_upgradable.
int rat_clean (rat_t *rat, uint64_t *freed_out, rat_error_t *err)
 remove the downloaded files of the cache.

Detailed Description

librat: the repository.

update the index, install a package by name, and the download cache.

the repository of this architecture is the url in the section [i686] or [x86_64] of <root>/etc/rat/repos.conf. it has index.conf, index.conf.sig and the package files. rat keeps the last good index in var/lib/rat (index.conf, index.conf.sig) and checks its signature each time it reads it. var/lib/rat/sequence has the largest sequence that rat accepted, so an old index is refused even when the saved index is damaged.

Macro Definition Documentation

◆ REPOS_FILE

#define REPOS_FILE   "etc/rat/repos.conf"

◆ INDEX_FILE

#define INDEX_FILE   RAT_DB_DIR "/index.conf"

◆ SIG_FILE

#define SIG_FILE   RAT_DB_DIR "/index.conf.sig"

◆ SEQUENCE_FILE

#define SEQUENCE_FILE   RAT_DB_DIR "/sequence"

◆ CACHE_DIR

#define CACHE_DIR   RAT_DB_DIR "/cache"

◆ INDEX_MAX

#define INDEX_MAX   (8u * 1024 * 1024)

the largest index and signature that rat downloads

◆ SIGNATURE_MAX

#define SIGNATURE_MAX   1024u

Function Documentation

◆ rat_index_load()

int rat_index_load ( rat_t * rat,
rat_index_t * index,
rat_error_t * err )

read the index that rat_update kept, and check its signature again.

Parameters
indexgets the index; free it with rat_index_free.
Returns
0, or -1 (also when there is no index yet).

◆ rat_update()

int rat_update ( rat_t * rat,
rat_progress_t progress,
void * context,
rat_update_t * result_out,
rat_error_t * err )

get the index of the repository (the url for this architecture in <root>/etc/rat/repos.conf) and its signature, check them, and keep them.

an index with a bad signature, or older than the one rat has, is refused and the old one stays.

Parameters
progressgets the progress of the download (may be NULL).
Returns
0, or -1.

◆ rat_install_name()

int rat_install_name ( rat_t * rat,
const char * name,
unsigned flags,
rat_note_t note,
rat_progress_t progress,
void * context,
rat_error_t * err )

install or upgrade a package of the index: download it into the cache, check its size and SHA-256 against the index, then install it as rat_install_file does.

the file leaves the cache after the install. a package that has the version of the index is refused before the download.

Parameters
flagsRAT_FORCE, RAT_DOWNGRADE, or 0.
notegets the notes of the install (may be NULL).
progressgets the progress of the download (may be NULL).
contextgoes to note and to progress.
Returns
0, or -1 with nothing changed.

◆ rat_upgradable()

int rat_upgradable ( rat_t * rat,
const rat_index_t * index,
rat_upgradable_t ** items_out,
int * count_out,
rat_error_t * err )

the installed packages that the index has in a newer version, sorted by name.

a package that is not in the index is not in the list.

Parameters
items_outgets an array to free with rat_upgradables_free; its remote pointers point into the index, so free it first.
Returns
0, or -1.

◆ rat_upgradables_free()

void rat_upgradables_free ( rat_upgradable_t * items,
int count )

release an array from rat_upgradable.

◆ rat_clean()

int rat_clean ( rat_t * rat,
uint64_t * freed_out,
rat_error_t * err )

remove the downloaded files of the cache.

Parameters
freed_outgets the bytes that were freed.
Returns
0, or -1.