|
ginnOS
The reference: libc, the libraries and the kernel
|
librat: the package manager of ginnOS. More...
Go to the source code of this file.
Data Structures | |
| struct | rat_error_t |
| a message about a failure More... | |
| struct | rat_entry_t |
| a folder, file or symbolic link of a package More... | |
| struct | rat_info_t |
| the fields of .RATINFO More... | |
| struct | rat_package_t |
| a package file that was read and checked More... | |
| struct | rat_remote_t |
| a package of the index of the repository More... | |
| struct | rat_index_t |
| the index of the repository, after its signature was checked More... | |
| struct | rat_update_t |
| what rat_update did More... | |
| struct | rat_upgradable_t |
| an installed package that the index has in a newer version More... | |
Macros | |
| #define | RAT_NAME_MAX 32 |
| #define | RAT_VERSION_MAX 32 |
| #define | RAT_ARCH_MAX 7 |
| #define | RAT_PATH_MAX 255 |
| #define | RAT_ERROR_MAX 512 |
| #define | RAT_DB_DIR "var/lib/rat" |
| the database folder, relative to the root | |
| #define | RAT_FORCE 0x1 |
| rat_install_file: replace files that exist and that no package owns | |
| #define | RAT_DOWNGRADE 0x2 |
| rat_install_file: replace an installed package with an older version | |
Typedefs | |
| typedef struct rat | rat_t |
| an open root folder | |
| typedef void(*) | rat_note_t(void *context, const char *text) |
| a function that gets the notes of a change (one line, without ' ') | |
| typedef void(*) | rat_progress_t(void *context, const char *file, uint64_t done, uint64_t total) |
| a function that gets the progress of a download. | |
Enumerations | |
| enum | rat_entry_type_t { RAT_ENTRY_FILE = 'f' , RAT_ENTRY_DIR = 'd' , RAT_ENTRY_LINK = 'l' } |
| the types of the members of a package More... | |
Functions | |
| rat_t * | rat_open (const char *root, bool write, rat_error_t *err) |
| open a root folder. | |
| void | rat_close (rat_t *rat) |
| close the handle and release the lock. | |
| const char * | rat_recovered (const rat_t *rat) |
| what rat_open did with an interrupted change. | |
| bool | rat_pending (const rat_t *rat) |
| true if a handle opened for queries saw an interrupted change, which the next rat_open for writing finishes. | |
| int | rat_package_read (const char *path, const char *arch, rat_package_t *package, rat_error_t *err) |
| read and check a package file. | |
| void | rat_package_free (rat_package_t *package) |
| release the memory of a package (not the struct itself). | |
| int | rat_install_file (rat_t *rat, const char *path, unsigned flags, rat_note_t note, void *context, rat_error_t *err) |
| install a package file. | |
| int | rat_remove (rat_t *rat, const char *name, rat_note_t note, void *context, rat_error_t *err) |
| remove an installed package: its files, its links, and its folders that are then empty and that the base or another package does not use. | |
| int | rat_list (rat_t *rat, rat_info_t **infos_out, int *count_out, rat_error_t *err) |
| the installed packages, sorted by name. | |
| int | rat_info (rat_t *rat, const char *name, rat_info_t *info_out, rat_error_t *err) |
| the fields of an installed package. | |
| int | rat_files (rat_t *rat, const char *name, rat_entry_t **entries_out, int *count_out, rat_error_t *err) |
| the folders, files and links of an installed package, sorted by path. | |
| int | rat_owner (rat_t *rat, const char *path, char name_out[RAT_NAME_MAX+1], rat_error_t *err) |
| which package owns a path. | |
| int | rat_verify (rat_t *rat, const char *name, rat_note_t note, void *context, int *problems_out, rat_error_t *err) |
| compare the files of an installed package with the record: a missing file, another type, other permissions, other data. | |
| bool | rat_root_in_ram (const rat_t *rat) |
| true if the root folder is the root image in RAM (from /proc/mounts): a change is then lost at the next boot. | |
| void | rat_info_free (rat_info_t *info) |
| release the strings of an info (not the struct itself). | |
| void | rat_infos_free (rat_info_t *infos, int count) |
| release an array from rat_list. | |
| void | rat_entries_free (rat_entry_t *entries, int count) |
| release an array from rat_files. | |
| bool | rat_name_ok (const char *name) |
| check a package name: 1 to RAT_NAME_MAX characters of a-z, 0-9, '-', '+' and '. | |
| int | rat_version_compare (const char *version_a, long release_a, const char *version_b, long release_b) |
| compare two versions of a package: first the versions, with the rules of Debian (digit runs as numbers, '~' before everything), then the releases. | |
| void | rat_index_free (rat_index_t *index) |
| release the memory of an index (not the struct itself). | |
| const rat_remote_t * | rat_index_find (const rat_index_t *index, const char *name) |
| a package of the index by name. | |
| bool | rat_remote_matches (const rat_remote_t *remote, const char *word) |
| true if word is in the name or the description of the package, without a difference between capitals and small letters. | |
| int | rat_index_similar (const rat_index_t *index, const char *name, const char **names_out, int max) |
| the names in the index that are near a name that it does not have, for a "did you mean" message: one or two letters different, or a name that contains it. | |
| 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_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_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. | |
librat: the package manager of ginnOS.
the rat command and other programs install, remove and inspect packages through it.
a package is a ustar archive, compressed with gzip, with the name <name>-<version>-<release>-<arch>.rat. its first member is .RATINFO (a libconf file with a [package] section); the other members are folders, files and symbolic links, with paths relative to the root folder.
every call works on a root folder: "/" on a running system, or another folder (a test, or an image that is not running). the database is in <root>/var/lib/rat. a change (install, remove) is a transaction: rat checks everything and unpacks into a stage folder first, then writes a list of operations and does them. if the change stops (a power cut), the next rat_open for writing does the rest of the list.
a function that can fail returns 0 or -1. on -1, the rat_error_t has a message for a person, without "rat:" at its start.
| #define RAT_NAME_MAX 32 |
| #define RAT_VERSION_MAX 32 |
| #define RAT_ARCH_MAX 7 |
| #define RAT_PATH_MAX 255 |
| #define RAT_ERROR_MAX 512 |
| #define RAT_DB_DIR "var/lib/rat" |
the database folder, relative to the root
| #define RAT_FORCE 0x1 |
rat_install_file: replace files that exist and that no package owns
| #define RAT_DOWNGRADE 0x2 |
rat_install_file: replace an installed package with an older version
| typedef void(*) rat_note_t(void *context, const char *text) |
a function that gets the notes of a change (one line, without '
')
a function that gets the progress of a download.
| file | the name of the file. |
| total | the size in bytes, or 0 while it is not known. |
| enum rat_entry_type_t |
| rat_t * rat_open | ( | const char * | root, |
| bool | write, | ||
| rat_error_t * | err ) |
open a root folder.
| root | the root folder; "/" on a running system. |
| write | true to change packages: takes the lock (one writer at a time), and finishes or removes an interrupted change. false for queries: no lock. |
| void rat_close | ( | rat_t * | rat | ) |
close the handle and release the lock.
| const char * rat_recovered | ( | const rat_t * | rat | ) |
what rat_open did with an interrupted change.
true if a handle opened for queries saw an interrupted change, which the next rat_open for writing finishes.
the queries can then show a state between the old one and the new one.
| int rat_package_read | ( | const char * | path, |
| const char * | arch, | ||
| rat_package_t * | package, | ||
| rat_error_t * | err ) |
read and check a package file.
nothing is written.
| arch | the architecture the package must have ("any" also matches), or NULL for every architecture. |
| void rat_package_free | ( | rat_package_t * | package | ) |
release the memory of a package (not the struct itself).
| int rat_install_file | ( | rat_t * | rat, |
| const char * | path, | ||
| unsigned | flags, | ||
| rat_note_t | note, | ||
| void * | context, | ||
| rat_error_t * | err ) |
install a package file.
when an older version of the package is installed, upgrade it: the files of the old version that the new one does not have go, in the same change. the same version is refused.
| flags | RAT_FORCE, RAT_DOWNGRADE (accept an older version than the installed one), or 0. |
| note | gets a line for each thing the person must know (may be NULL). |
| int rat_remove | ( | rat_t * | rat, |
| const char * | name, | ||
| rat_note_t | note, | ||
| void * | context, | ||
| rat_error_t * | err ) |
remove an installed package: its files, its links, and its folders that are then empty and that the base or another package does not use.
| note | gets a line for each file that was changed after the install. |
| int rat_list | ( | rat_t * | rat, |
| rat_info_t ** | infos_out, | ||
| int * | count_out, | ||
| rat_error_t * | err ) |
the installed packages, sorted by name.
| infos_out | gets an array to free with rat_infos_free. |
| int rat_info | ( | rat_t * | rat, |
| const char * | name, | ||
| rat_info_t * | info_out, | ||
| rat_error_t * | err ) |
the fields of an installed package.
| int rat_files | ( | rat_t * | rat, |
| const char * | name, | ||
| rat_entry_t ** | entries_out, | ||
| int * | count_out, | ||
| rat_error_t * | err ) |
the folders, files and links of an installed package, sorted by path.
| entries_out | gets an array to free with rat_entries_free. |
| int rat_owner | ( | rat_t * | rat, |
| const char * | path, | ||
| char | name_out[RAT_NAME_MAX+1], | ||
| rat_error_t * | err ) |
which package owns a path.
| path | an absolute path on the root, as "/usr/bin/lua". |
| name_out | gets the package name, or "" when the base image owns the path. |
| int rat_verify | ( | rat_t * | rat, |
| const char * | name, | ||
| rat_note_t | note, | ||
| void * | context, | ||
| int * | problems_out, | ||
| rat_error_t * | err ) |
compare the files of an installed package with the record: a missing file, another type, other permissions, other data.
| note | gets one line for each difference. |
| problems_out | gets the number of differences. |
true if the root folder is the root image in RAM (from /proc/mounts): a change is then lost at the next boot.
always false for a root other than "/".
| void rat_info_free | ( | rat_info_t * | info | ) |
release the strings of an info (not the struct itself).
| void rat_infos_free | ( | rat_info_t * | infos, |
| int | count ) |
release an array from rat_list.
| void rat_entries_free | ( | rat_entry_t * | entries, |
| int | count ) |
release an array from rat_files.
| bool rat_name_ok | ( | const char * | name | ) |
check a package name: 1 to RAT_NAME_MAX characters of a-z, 0-9, '-', '+' and '.
', the first a letter or a digit.
| int rat_version_compare | ( | const char * | version_a, |
| long | release_a, | ||
| const char * | version_b, | ||
| long | release_b ) |
compare two versions of a package: first the versions, with the rules of Debian (digit runs as numbers, '~' before everything), then the releases.
| void rat_index_free | ( | rat_index_t * | index | ) |
release the memory of an index (not the struct itself).
| const rat_remote_t * rat_index_find | ( | const rat_index_t * | index, |
| const char * | name ) |
a package of the index by name.
| bool rat_remote_matches | ( | const rat_remote_t * | remote, |
| const char * | word ) |
true if word is in the name or the description of the package, without a difference between capitals and small letters.
| int rat_index_similar | ( | const rat_index_t * | index, |
| const char * | name, | ||
| const char ** | names_out, | ||
| int | max ) |
the names in the index that are near a name that it does not have, for a "did you mean" message: one or two letters different, or a name that contains it.
| names_out | gets pointers into the index. |
| 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.
| progress | gets the progress of the download (may be NULL). |
| 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.
| index | gets the index; free it with rat_index_free. |
| 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.
| flags | RAT_FORCE, RAT_DOWNGRADE, or 0. |
| note | gets the notes of the install (may be NULL). |
| progress | gets the progress of the download (may be NULL). |
| context | goes to note and to progress. |
| 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.
| items_out | gets an array to free with rat_upgradables_free; its remote pointers point into the index, so free it first. |
| 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.
| freed_out | gets the bytes that were freed. |