libalpm
Arch Linux Package Manager Library
be_local.c File Reference
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <sys/stat.h>
#include <dirent.h>
#include <limits.h>
#include <archive.h>
#include <archive_entry.h>
#include "db.h"
#include "alpm_list.h"
#include "libarchive-compat.h"
#include "log.h"
#include "util.h"
#include "alpm.h"
#include "handle.h"
#include "package.h"
#include "deps.h"
#include "filelist.h"
Include dependency graph for be_local.c:

Macros

#define LAZY_LOAD(info)
 
#define READ_NEXT()
 
#define READ_AND_STORE(f)
 
#define READ_AND_STORE_ALL(f)
 
#define READ_AND_SPLITDEP(f)
 

Functions

static int local_db_read (alpm_pkg_t *info, int inforeq)
 
static const char * _cache_get_base (alpm_pkg_t *pkg)
 
static const char * _cache_get_desc (alpm_pkg_t *pkg)
 
static const char * _cache_get_url (alpm_pkg_t *pkg)
 
static alpm_time_t _cache_get_builddate (alpm_pkg_t *pkg)
 
static alpm_time_t _cache_get_installdate (alpm_pkg_t *pkg)
 
static const char * _cache_get_packager (alpm_pkg_t *pkg)
 
static const char * _cache_get_arch (alpm_pkg_t *pkg)
 
static off_t _cache_get_isize (alpm_pkg_t *pkg)
 
static alpm_pkgreason_t _cache_get_reason (alpm_pkg_t *pkg)
 
static int _cache_get_validation (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_licenses (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_groups (alpm_pkg_t *pkg)
 
static int _cache_has_scriptlet (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_depends (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_optdepends (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_makedepends (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_checkdepends (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_conflicts (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_provides (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_replaces (alpm_pkg_t *pkg)
 
static alpm_filelist_t_cache_get_files (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_backup (alpm_pkg_t *pkg)
 
static alpm_list_t_cache_get_xdata (alpm_pkg_t *pkg)
 
static void * _cache_changelog_open (alpm_pkg_t *pkg)
 Open a package changelog for reading.
 
static size_t _cache_changelog_read (void *ptr, size_t size, const alpm_pkg_t UNUSED *pkg, void *fp)
 Read data from an open changelog 'file stream'.
 
static int _cache_changelog_close (const alpm_pkg_t UNUSED *pkg, void *fp)
 Close a package changelog for reading.
 
static struct archive * _cache_mtree_open (alpm_pkg_t *pkg)
 Open a package mtree file for reading.
 
static int _cache_mtree_next (const alpm_pkg_t UNUSED *pkg, struct archive *mtree, struct archive_entry **entry)
 Read next entry from a package mtree file.
 
static int _cache_mtree_close (const alpm_pkg_t UNUSED *pkg, struct archive *mtree)
 Close a package mtree file for reading.
 
static int _cache_force_load (alpm_pkg_t *pkg)
 
static int checkdbdir (alpm_db_t *db)
 
static int is_dir (const char *path, struct dirent *entry)
 
static int local_db_add_version (alpm_db_t UNUSED *db, const char *dbpath)
 
static int local_db_create (alpm_db_t *db, const char *dbpath)
 
static int local_db_validate (alpm_db_t *db)
 
static int local_db_populate (alpm_db_t *db)
 
static alpm_pkgreason_t _read_pkgreason (alpm_handle_t *handle, const char *pkgname, const char *line)
 
static void write_deps (FILE *fp, const char *header, alpm_list_t *deplist)
 
int alpm_pkg_set_reason (alpm_pkg_t *pkg, alpm_pkgreason_t reason)
 Set install reason for a package in the local database.
 

Variables

size_t ALPM_LOCAL_DB_VERSION = 9
 
static const struct pkg_operations local_pkg_ops
 The local database operations struct.
 
static const struct db_operations local_db_ops
 

Macro Definition Documentation

◆ LAZY_LOAD

◆ READ_AND_SPLITDEP

#define READ_AND_SPLITDEP ( f)
Value:
do { \
if(safe_fgets(line, sizeof(line), fp) == NULL) {\
if(!feof(fp)) goto error; else break; \
} \
if(_alpm_strip_newline(line, 0) == 0) break; \
} while(1) /* note the while(1) and not (0) */
alpm_depend_t * alpm_dep_from_string(const char *depstring)
Return a newly allocated dependency information parsed from a string should be used to free the depen...
Definition deps.c:458
alpm_list_t * alpm_list_add(alpm_list_t *list, void *data)
Add a new item to the end of the list.
Definition alpm_list.c:64
#define error(...)

Referenced by local_db_read().

◆ READ_AND_STORE

#define READ_AND_STORE ( f)
Value:
do { \
READ_NEXT(); \
STRDUP(f, line, goto error); \
} while(0)

Referenced by local_db_read().

◆ READ_AND_STORE_ALL

#define READ_AND_STORE_ALL ( f)
Value:
do { \
char *linedup; \
if(safe_fgets(line, sizeof(line), fp) == NULL) {\
if(!feof(fp)) goto error; else break; \
} \
if(_alpm_strip_newline(line, 0) == 0) break; \
STRDUP(linedup, line, goto error); \
f = alpm_list_add(f, linedup); \
} while(1) /* note the while(1) and not (0) */
#define STRDUP(r, s, action)
Definition util.h:58

Referenced by local_db_read().

◆ READ_NEXT

#define READ_NEXT ( )
Value:
do { \
if(safe_fgets(line, sizeof(line), fp) == NULL && !feof(fp)) goto error; \
_alpm_strip_newline(line, 0); \
} while(0)

Referenced by local_db_read().

Function Documentation

◆ _cache_changelog_close()

static int _cache_changelog_close ( const alpm_pkg_t UNUSED * pkg,
void * fp )
static

Close a package changelog for reading.

Similar to fclose in functionality, except that the 'file stream' is from the database.

Parameters
pkgthe package that the changelog was read from
fpa 'file stream' to the package changelog
Returns
whether closing the package changelog stream was successful

◆ _cache_changelog_open()

static void * _cache_changelog_open ( alpm_pkg_t * pkg)
static

Open a package changelog for reading.

Similar to fopen in functionality, except that the returned 'file stream' is from the database.

Parameters
pkgthe package (from db) to read the changelog
Returns
a 'file stream' to the package changelog

References alpm_pkg_get_db().

◆ _cache_changelog_read()

static size_t _cache_changelog_read ( void * ptr,
size_t size,
const alpm_pkg_t UNUSED * pkg,
void * fp )
static

Read data from an open changelog 'file stream'.

Similar to fread in functionality, this function takes a buffer and amount of data to read.

Parameters
ptra buffer to fill with raw changelog data
sizethe size of the buffer
pkgthe package that the changelog is being read from
fpa 'file stream' to the package changelog
Returns
the number of characters read, or 0 if there is no more data

◆ _cache_force_load()

static int _cache_force_load ( alpm_pkg_t * pkg)
static

References INFRQ_ALL, and local_db_read().

◆ _cache_get_arch()

static const char * _cache_get_arch ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_backup()

static alpm_list_t * _cache_get_backup ( alpm_pkg_t * pkg)
static

References INFRQ_FILES, and LAZY_LOAD.

◆ _cache_get_base()

static const char * _cache_get_base ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_builddate()

static alpm_time_t _cache_get_builddate ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_checkdepends()

static alpm_list_t * _cache_get_checkdepends ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_conflicts()

static alpm_list_t * _cache_get_conflicts ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_depends()

static alpm_list_t * _cache_get_depends ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_desc()

static const char * _cache_get_desc ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_files()

static alpm_filelist_t * _cache_get_files ( alpm_pkg_t * pkg)
static

References INFRQ_FILES, and LAZY_LOAD.

◆ _cache_get_groups()

static alpm_list_t * _cache_get_groups ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_installdate()

static alpm_time_t _cache_get_installdate ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_isize()

static off_t _cache_get_isize ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_licenses()

static alpm_list_t * _cache_get_licenses ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_makedepends()

static alpm_list_t * _cache_get_makedepends ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_optdepends()

static alpm_list_t * _cache_get_optdepends ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_packager()

static const char * _cache_get_packager ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_provides()

static alpm_list_t * _cache_get_provides ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_reason()

static alpm_pkgreason_t _cache_get_reason ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_replaces()

static alpm_list_t * _cache_get_replaces ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_url()

static const char * _cache_get_url ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_validation()

static int _cache_get_validation ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_get_xdata()

static alpm_list_t * _cache_get_xdata ( alpm_pkg_t * pkg)
static

References INFRQ_DESC, and LAZY_LOAD.

◆ _cache_has_scriptlet()

static int _cache_has_scriptlet ( alpm_pkg_t * pkg)
static

References INFRQ_SCRIPTLET, and LAZY_LOAD.

◆ _cache_mtree_close()

static int _cache_mtree_close ( const alpm_pkg_t UNUSED * pkg,
struct archive * mtree )
static

Close a package mtree file for reading.

Parameters
pkgthe package that the mtree file was read from
mtreethe archive structure use for reading from the mtree file
Returns
whether closing the package changelog stream was successful

◆ _cache_mtree_next()

static int _cache_mtree_next ( const alpm_pkg_t UNUSED * pkg,
struct archive * mtree,
struct archive_entry ** entry )
static

Read next entry from a package mtree file.

Parameters
pkgthe package that the mtree file is being read from
archivethe archive structure reading from the mtree file
entryan archive_entry to store the entry header information
Returns
0 on success, 1 if end of archive is reached, -1 otherwise.

◆ _cache_mtree_open()

static struct archive * _cache_mtree_open ( alpm_pkg_t * pkg)
static

Open a package mtree file for reading.

Parameters
pkgthe local package to read the changelog of
Returns
a archive structure for the package mtree file

References _, ALPM_BUFFER_SIZE, ALPM_ERR_LIBARCHIVE, ALPM_LOG_ERROR, alpm_pkg_get_db(), error, and GOTO_ERR.

◆ _read_pkgreason()

static alpm_pkgreason_t _read_pkgreason ( alpm_handle_t * handle,
const char * pkgname,
const char * line )
static

◆ checkdbdir()

static int checkdbdir ( alpm_db_t * db)
static

◆ is_dir()

static int is_dir ( const char * path,
struct dirent * entry )
static

◆ local_db_add_version()

static int local_db_add_version ( alpm_db_t UNUSED * db,
const char * dbpath )
static

◆ local_db_create()

static int local_db_create ( alpm_db_t * db,
const char * dbpath )
static

◆ local_db_populate()

◆ local_db_read()

◆ local_db_validate()

◆ write_deps()

static void write_deps ( FILE * fp,
const char * header,
alpm_list_t * deplist )
static

Variable Documentation

◆ ALPM_LOCAL_DB_VERSION

size_t ALPM_LOCAL_DB_VERSION = 9

◆ local_db_ops

const struct db_operations local_db_ops
static
Initial value:
= {
.validate = local_db_validate,
.populate = local_db_populate,
.unregister = _alpm_db_unregister,
}
static int local_db_validate(alpm_db_t *db)
Definition be_local.c:444
static int local_db_populate(alpm_db_t *db)
Definition be_local.c:533

◆ local_pkg_ops

const struct pkg_operations local_pkg_ops
static

The local database operations struct.

Get package fields through lazy accessor methods that handle any backend loading and caching logic.

Referenced by local_db_populate().