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

Data Structures

struct  package_changelog
 

Macros

#define MAX_SIGFILE_SIZE   16384
 

Functions

static void * _package_changelog_open (alpm_pkg_t *pkg)
 Open a package changelog for reading.
 
static size_t _package_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 _package_changelog_close (const alpm_pkg_t UNUSED *pkg, void *fp)
 Close a package changelog for reading.
 
static const struct pkg_operationsget_file_pkg_ops (void)
 Package file operations struct accessor.
 
static int parse_descfile (alpm_handle_t *handle, struct archive *a, alpm_pkg_t *newpkg)
 Parses the package description file for a package into a alpm_pkg_t struct.
 
static int handle_simple_path (alpm_pkg_t *pkg, const char *path)
 Handle the existence of simple paths for _alpm_load_pkg_internal()
 
static int add_entry_to_files_list (alpm_filelist_t *filelist, size_t *files_size, struct archive_entry *entry, const char *path)
 Add a file to the files list for pkg.
 
static int build_filelist_from_mtree (alpm_handle_t *handle, alpm_pkg_t *pkg, struct archive *archive)
 Generate a new file list from an mtree file and add it to the package.
 
static int read_sigfile (const char *sigpath, unsigned char **sig)
 
int alpm_pkg_load (alpm_handle_t *handle, const char *filename, int full, int level, alpm_pkg_t **pkg)
 Create a package from a file.
 

Data Structure Documentation

◆ package_changelog

struct package_changelog
Data Fields
struct archive * archive
int fd

Macro Definition Documentation

◆ MAX_SIGFILE_SIZE

#define MAX_SIGFILE_SIZE   16384

Referenced by read_sigfile().

Function Documentation

◆ _package_changelog_close()

static int _package_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 an archive.

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

References package_changelog::archive, and package_changelog::fd.

Referenced by get_file_pkg_ops().

◆ _package_changelog_open()

static void * _package_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 an archive.

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

References ALPM_ERR_MEMORY, ALPM_ERR_PKG_OPEN, package_changelog::archive, ASSERT, and package_changelog::fd.

Referenced by get_file_pkg_ops().

◆ _package_changelog_read()

static size_t _package_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

References ALPM_ERR_LIBARCHIVE, package_changelog::archive, and RET_ERR.

Referenced by get_file_pkg_ops().

◆ add_entry_to_files_list()

static int add_entry_to_files_list ( alpm_filelist_t * filelist,
size_t * files_size,
struct archive_entry * entry,
const char * path )
static

Add a file to the files list for pkg.

Parameters
pkgpackage to add the file to
files_sizesize of pkg->files.files
entryarchive entry of the file to add to the list
pathpath of the file to be added
Returns
<0 on error, 0 on success

References alpm_filelist_t::count, alpm_filelist_t::files, MALLOC, alpm_file_t::mode, alpm_file_t::name, alpm_file_t::size, and STRDUP.

Referenced by build_filelist_from_mtree().

◆ build_filelist_from_mtree()

static int build_filelist_from_mtree ( alpm_handle_t * handle,
alpm_pkg_t * pkg,
struct archive * archive )
static

Generate a new file list from an mtree file and add it to the package.

An existing file list will be free()d first.

archive should point to an archive struct which is already at the position of the mtree's header.

Parameters
handle
pkgpackage to add the file list to
archivearchive containing the mtree
Returns
0 on success, <0 on error

References _, add_entry_to_files_list(), ALPM_BUFFER_SIZE, ALPM_ERR_LIBARCHIVE, ALPM_LOG_DEBUG, alpm_filelist_t::count, error, alpm_filelist_t::files, GOTO_ERR, handle_simple_path(), alpm_file_t::name, and archive_read_buffer::ret.

◆ get_file_pkg_ops()

static const struct pkg_operations * get_file_pkg_ops ( void )
static

Package file operations struct accessor.

We implement this as a method because we want to reuse the majority of the default_pkg_ops struct and add only a few operations of our own on top.

References _package_changelog_close(), _package_changelog_open(), _package_changelog_read(), pkg_operations::changelog_close, pkg_operations::changelog_open, pkg_operations::changelog_read, and default_pkg_ops.

◆ handle_simple_path()

static int handle_simple_path ( alpm_pkg_t * pkg,
const char * path )
static

Handle the existence of simple paths for _alpm_load_pkg_internal()

Parameters
pkgpackage to change
pathpath to examine
Returns
0 if path doesn't match any rule, 1 if it has been handled

Referenced by build_filelist_from_mtree().

◆ parse_descfile()

static int parse_descfile ( alpm_handle_t * handle,
struct archive * a,
alpm_pkg_t * newpkg )
static

Parses the package description file for a package into a alpm_pkg_t struct.

Parameters
archivethe archive to read from, pointed at the .PKGINFO entry
newpkgan empty alpm_pkg_t struct to fill with package info
Returns
0 on success, -1 on error

References _, alpm_dep_from_string(), alpm_list_add(), alpm_list_append(), ALPM_LOG_DEBUG, ALPM_LOG_WARNING, CALLOC, FREE, archive_read_buffer::line, archive_read_buffer::max_line_size, alpm_backup_t::name, archive_read_buffer::real_line_size, archive_read_buffer::ret, and STRDUP.

◆ read_sigfile()

static int read_sigfile ( const char * sigpath,
unsigned char ** sig )
static

References MALLOC, and MAX_SIGFILE_SIZE.

Referenced by alpm_pkg_load().