createrepo_c library 1.2.0
C library for metadata manipulation
Loading...
Searching...
No Matches
Miscellaneous useful functions and macros.

Data Structures

struct  cr_EVR
 
struct  cr_NEVR
 
struct  cr_NEVRA
 
struct  cr_Version
 
struct  cr_HeaderRangeStruct
 

Macros

#define CR_STATICSTRLEN(s)   (sizeof(s)/sizeof(s[0]))
 
#define CR_ARRAYLEN(x)   ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
 
#define cr_compress_file(SRC, DST, COMTYPE, ZCK_DICT_DIR, ZCK_AUTO_CHUNK, ERR)
 
#define cr_decompress_file(SRC, DST, COMTYPE, ERR)    cr_decompress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)
 
#define cr_cmp_nevra(A, B)
 

Enumerations

enum  cr_CpFlags { CR_CP_DEFAULT = (1<<0) , CR_CP_RECURSIVE = (1<<1) , CR_CP_PRESERVE_ALL = (1<<2) }
 
enum  cr_RmFlags { CR_RM_DEFAULT = (1<<0) , CR_RM_RECURSIVE = (1<<1) , CR_RM_FORCE = (1<<2) }
 

Functions

const char * cr_flag_to_str (gint64 flags)
 
cr_EVRcr_str_to_evr (const char *string, GStringChunk *chunk)
 
void cr_evr_free (cr_EVR *evr)
 
struct cr_HeaderRangeStruct cr_get_header_byte_range (const char *filename, GError **err)
 
char * cr_get_filename (const char *filepath)
 
char * cr_get_cleaned_href (const char *filepath)
 
int cr_download (CURL *handle, const char *url, const char *destination, GError **err)
 
gboolean cr_copy_file (const char *src, const char *dst, GError **err)
 
int cr_compress_file_with_stat (const char *src, const char *dst, cr_CompressionType comtype, cr_ContentStat *stat, const char *zck_dict_dir, gboolean zck_auto_chunk, GError **err)
 
int cr_decompress_file_with_stat (const char *src, const char *dst, cr_CompressionType comtype, cr_ContentStat *stat, GError **err)
 
gboolean cr_better_copy_file (const char *src, const char *dst, GError **err)
 
int cr_remove_dir (const char *path, GError **err)
 
gboolean cr_move_recursive (const char *srcDir, const char *dstDir, GError **err)
 
char * cr_normalize_dir_path (const char *path)
 
struct cr_Version cr_str_to_version (const char *str)
 
int cr_cmp_version_str (const char *str1, const char *str2)
 
void cr_null_log_fn (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
 
void cr_log_fn (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
 
void cr_slist_free_full (GSList *list, GDestroyNotify free_f)
 
void cr_queue_free_full (GQueue *queue, GDestroyNotify free_f)
 
cr_NEVRAcr_split_rpm_filename (const char *filename)
 
int cr_cmp_evr (const char *e1, const char *v1, const char *r1, const char *e2, const char *v2, const char *r2)
 
int cr_warning_cb (cr_XmlParserWarningType type, char *msg, void *cbdata, GError **err)
 
gboolean cr_write_to_file (GError **err, gchar *filename, const char *format,...)
 
gboolean cr_cp (const char *src, const char *dst, cr_CpFlags flags, const char *working_directory, GError **err) __attribute__((deprecated("please use `cr_gio_cp` instead")))
 
gboolean cr_gio_cp (GFile *src, GFile *dst, GFileCopyFlags flags, GCancellable *cancellable, GError **err)
 
gboolean cr_rm (const char *path, cr_RmFlags flags, const char *working_dir, GError **err)
 
gchar * cr_append_pid_and_datetime (const char *str, const char *suffix)
 
gboolean cr_spawn_check_exit_status (gint exit_status, GError **error)
 
cr_NEVRcr_str_to_nevr (const char *str)
 
void cr_nevr_free (cr_NEVR *nevr)
 
cr_NEVRAcr_str_to_nevra (const char *str)
 
void cr_nevra_free (cr_NEVRA *nevra)
 
gboolean cr_identical_files (const gchar *fn1, const gchar *fn2, gboolean *identical, GError **err)
 
gchar * cr_cut_dirs (gchar *path, gint cut_dirs)
 
const gchar * cr_version_string_with_features (void)
 
gchar * cr_get_dict_file (const gchar *dir, const gchar *file)
 

Detailed Description

Macro Definition Documentation

◆ CR_ARRAYLEN

#define CR_ARRAYLEN ( x)    ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))

Definition at line 45 of file misc.h.

◆ cr_cmp_nevra

#define cr_cmp_nevra ( A,
B )
Value:
(cr_cmp_evr((A)->epoch, (A)->version, (A)->release,\
(B)->epoch, (B)->version, (B)->release))
int cr_cmp_evr(const char *e1, const char *v1, const char *r1, const char *e2, const char *v2, const char *r2)

Compare evr of two cr_NEVRA. Name and arch are ignored.

Parameters
Apointer to first cr_NEVRA
Bpointer to second cr_NEVRA
Returns
0 = same, 1 = first is newer, -1 = second is newer

Definition at line 340 of file misc.h.

◆ cr_compress_file

#define cr_compress_file ( SRC,
DST,
COMTYPE,
ZCK_DICT_DIR,
ZCK_AUTO_CHUNK,
ERR )
Value:
cr_compress_file_with_stat(SRC, DST, COMTYPE, NULL, ZCK_DICT_DIR, \
ZCK_AUTO_CHUNK, ERR)
int cr_compress_file_with_stat(const char *src, const char *dst, cr_CompressionType comtype, cr_ContentStat *stat, const char *zck_dict_dir, gboolean zck_auto_chunk, GError **err)

Compress file.

Parameters
SRCsource filename
DSTdestination (If dst is dir, filename of src + compression suffix is used. If dst is NULL, src + compression suffix is used)
COMTYPEtype of compression
ZCK_DICT_DIRLocation of zchunk zdicts (if zchunk is enabled)
ZCK_AUTO_CHUNKWhether zchunk file should be auto-chunked
ERRGError **
Returns
cr_Error return code

Definition at line 184 of file misc.h.

◆ cr_decompress_file

#define cr_decompress_file ( SRC,
DST,
COMTYPE,
ERR )    cr_decompress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)

Decompress file.

Parameters
SRCsource filename
DSTdestination (If dst is dir, filename of src without compression suffix (if present) is used. If dst is NULL, src without compression suffix is used) Otherwise ".decompressed" suffix is used
COMTYPEtype of compression
ERRGError **
Returns
cr_Error return code

Definition at line 218 of file misc.h.

◆ CR_STATICSTRLEN

#define CR_STATICSTRLEN ( s)    (sizeof(s)/sizeof(s[0]))

Lenght of static string (including last '\0' byte)

Definition at line 41 of file misc.h.

Enumeration Type Documentation

◆ cr_CpFlags

enum cr_CpFlags
Enumerator
CR_CP_DEFAULT 

No attributes - default

CR_CP_RECURSIVE 

Copy directories recursively

CR_CP_PRESERVE_ALL 

preserve the all attributes (if possible)

Definition at line 444 of file misc.h.

◆ cr_RmFlags

enum cr_RmFlags
Enumerator
CR_RM_DEFAULT 

No attributes - default

CR_RM_RECURSIVE 

Copy directories recursively

CR_RM_FORCE 

Use force

Definition at line 481 of file misc.h.

Function Documentation

◆ cr_append_pid_and_datetime()

gchar * cr_append_pid_and_datetime ( const char * str,
const char * suffix )

Append "YYYYmmddHHMMSS.MICROSECONDS.PID" suffix to the str.

Parameters
strString or NULL
suffixAnother string that will be appended or NULL
returnNewly allocated string

◆ cr_better_copy_file()

gboolean cr_better_copy_file ( const char * src,
const char * dst,
GError ** err )

Better copy file. Source (src) could be remote address (http:// or ftp://).

Parameters
srcsource filename
dstdestination (if dst is dir, filename of src is used)
errGError **
Returns
TRUE on success, FALSE if an error occured

◆ cr_cmp_evr()

int cr_cmp_evr ( const char * e1,
const char * v1,
const char * r1,
const char * e2,
const char * v2,
const char * r2 )

Compare two version strings splited into evr chunks.

Parameters
e11. epoch
v11. version
r11. release
e22. epoch
v22. version
r22. release
Returns
0 = same, 1 = first is newer, -1 = second is newer

◆ cr_cmp_version_str()

int cr_cmp_version_str ( const char * str1,
const char * str2 )

Compare two version string.

Parameters
str1first version string
str2second version string
Returns
0 - versions are same, 1 - first string is bigger version, 2 - second string is bigger version

◆ cr_compress_file_with_stat()

int cr_compress_file_with_stat ( const char * src,
const char * dst,
cr_CompressionType comtype,
cr_ContentStat * stat,
const char * zck_dict_dir,
gboolean zck_auto_chunk,
GError ** err )

Compress file.

Parameters
srcsource filename
dstdestination (If dst is dir, filename of src + compression suffix is used. If dst is NULL, src + compression suffix is used)
comtypetype of compression
statpointer to cr_ContentStat or NULL
zck_dict_dirLocation of zchunk zdicts (if zchunk is enabled)
zck_auto_chunkWhether zchunk file should be auto-chunked
errGError **
Returns
cr_Error return code

◆ cr_copy_file()

gboolean cr_copy_file ( const char * src,
const char * dst,
GError ** err )

Copy file.

Parameters
srcsource filename
dstdestination (if dst is dir, filename of src is used)
errGError **
Returns
TRUE on success, FALSE if an error occured

◆ cr_cp()

gboolean cr_cp ( const char * src,
const char * dst,
cr_CpFlags flags,
const char * working_directory,
GError ** err )

Wrapper for cp

Parameters
srcSource (supports wildcards)
dstDestination (supports wildcards)
flagsFlags
working_dirWorking directory
errGError **

◆ cr_cut_dirs()

gchar * cr_cut_dirs ( gchar * path,
gint cut_dirs )

Cut first N components of path. Note: Basename is never cut out.

◆ cr_decompress_file_with_stat()

int cr_decompress_file_with_stat ( const char * src,
const char * dst,
cr_CompressionType comtype,
cr_ContentStat * stat,
GError ** err )

Decompress file.

Parameters
srcsource filename
dstdestination (If dst is dir, filename of src without compression suffix (if present) is used. If dst is NULL, src without compression suffix is used) Otherwise ".decompressed" suffix is used
comtypetype of compression
statpointer to cr_ContentStat or NULL
errGError **
Returns
cr_Error return code

◆ cr_download()

int cr_download ( CURL * handle,
const char * url,
const char * destination,
GError ** err )

Download a file from the URL into the in_dst via curl handle.

Parameters
handleCURL handle
urlsource url
destinationdestination (if destination is dir, filename from the url is used)
errGError **
Returns
cr_Error

◆ cr_evr_free()

void cr_evr_free ( cr_EVR * evr)

Free cr_EVR Warning: Do not use this function when a string chunk was used in the cr_str_to_evr! In that case use only g_free on the cr_EVR pointer.

Parameters
evrcr_EVR structure

◆ cr_flag_to_str()

const char * cr_flag_to_str ( gint64 flags)

Convert flags from RPM header to a string representation.

Parameters
flagsflags
Returns
flags as constant string

◆ cr_get_cleaned_href()

char * cr_get_cleaned_href ( const char * filepath)

Return pointer to the rest of string after './' prefix. (e.g. for "././foo/bar" returns "foo/bar")

Parameters
filepathpath
Returns
pointer into the path

◆ cr_get_dict_file()

gchar * cr_get_dict_file ( const gchar * dir,
const gchar * file )

Get dict file from dict directory This functions returns a zchunk dictionary file from the zchunk dictionary directory that matches the passed filename. If no zchunk dictionary file exists or no dictionary directory is set, this function returns NULL

The zchunk dictionary file must be the same as the passed filename with a ".zdict" extension

Parameters
dirZchunk dictionary directory
fileFile being zchunked
Returns
NULL if no matching file exists, or the full path to the file otherwise

◆ cr_get_filename()

char * cr_get_filename ( const char * filepath)

Return pointer to the rest of string after last '/'. (e.g. for "/foo/bar" returns "bar")

Parameters
filepathpath
Returns
pointer into the path

◆ cr_get_header_byte_range()

struct cr_HeaderRangeStruct cr_get_header_byte_range ( const char * filename,
GError ** err )

Return header byte range.

Parameters
filenamefilename
errGError **
Returns
header range (start = end = 0 on error)

◆ cr_gio_cp()

gboolean cr_gio_cp ( GFile * src,
GFile * dst,
GFileCopyFlags flags,
GCancellable * cancellable,
GError ** err )

Recursive copy of directory (works on files as well)

Parameters
srcSource (supports wildcards)
dstDestination (supports wildcards)
flagsFlags
cancellableCan this be cancelled by another thread?
errGError **

◆ cr_identical_files()

gboolean cr_identical_files ( const gchar * fn1,
const gchar * fn2,
gboolean * identical,
GError ** err )

Are the files identical? Different paths could point to the same file. This functions checks if both paths point to the same file or not. If one of the files doesn't exist, the funcion doesn't fail and just put FALSE into "indentical" value and returns.

Parameters
fn1First path
fn2Second path
identicalAre the files same or not
errGError **
Returns
FALSE if an error was encountered, TRUE otherwise

◆ cr_log_fn()

void cr_log_fn ( const gchar * log_domain,
GLogLevelFlags log_level,
const gchar * message,
gpointer user_data )

Createrepo_c library standard logging function.

Parameters
log_domainlogging domain
log_levellogging level
messagemessage
user_datauser data

◆ cr_move_recursive()

gboolean cr_move_recursive ( const char * srcDir,
const char * dstDir,
GError ** err )

Move a directory and its contents. Native move is preferred, if not supported copy and delete fallback is used.

Parameters
srcDirA source directory path
dstDirA destination directory path
errGError **
Returns
TRUE on success, FALSE otherwise

◆ cr_nevr_free()

void cr_nevr_free ( cr_NEVR * nevr)

Free cr_NEVR

Parameters
nevrcr_NEVR structure

◆ cr_nevra_free()

void cr_nevra_free ( cr_NEVRA * nevra)

Free cr_NEVRA

Parameters
nevracr_NEVRA structure

◆ cr_normalize_dir_path()

char * cr_normalize_dir_path ( const char * path)

Normalize path (Path with exactly one trailing '/').

Parameters
pathpath
Returns
mallocated string with normalized path or NULL

◆ cr_null_log_fn()

void cr_null_log_fn ( const gchar * log_domain,
GLogLevelFlags log_level,
const gchar * message,
gpointer user_data )

Logging function with no output.

Parameters
log_domainlogging domain
log_levellogging level
messagemessage
user_datauser data

◆ cr_queue_free_full()

void cr_queue_free_full ( GQueue * queue,
GDestroyNotify free_f )

Convenience method, which frees all the memory used by a GQueue, and calls the specified destroy function on every element's data. This is the same function as g_queue_free_full(). The original function is implemented in glib since 2.32 but we need to support the older glib too.

Parameters
queuea pointer to a GQueue
thefunction to be called to free each element's data

◆ cr_remove_dir()

int cr_remove_dir ( const char * path,
GError ** err )

Recursively remove directory.

Parameters
pathfilepath
errGError **
Returns
cr_Error return code

◆ cr_rm()

gboolean cr_rm ( const char * path,
cr_RmFlags flags,
const char * working_dir,
GError ** err )

Wrapper over rm command

Parameters
pathPath (supports wildcards)
flagsFlags
working_dirWorking directory
errGError **

◆ cr_slist_free_full()

void cr_slist_free_full ( GSList * list,
GDestroyNotify free_f )

Frees all the memory used by a GSList, and calls the specified destroy function on every element's data. This is the same function as g_slist_free_full(). The original function is implemented in glib since 2.28 but we need to support the older glib too.

Parameters
listpointer to GSList
free_fthe function to be called to free each element's data

◆ cr_spawn_check_exit_status()

gboolean cr_spawn_check_exit_status ( gint exit_status,
GError ** error )

Createrepo_c's reimplementation of convinient g_spawn_check_exit_status() function which is available since glib 2.34 (createrepo_c is currently compatible with glib >= 2.28)

Parameters
exit_statusAn exit code as returned from g_spawn_sync()
errorGError **
Returns
TRUE if child exited successfully, FALSE otherwise (and error will be set)

◆ cr_split_rpm_filename()

cr_NEVRA * cr_split_rpm_filename ( const char * filename)

Split filename into the NEVRA. Supported formats: [path/]N-V-R:E.A[.rpm] [path/]E:N-V-R.A[.rpm] [path/]N-E:V-R.A[.rpm] [path/]N-V-R.A[.rpm]:E

Parameters
filenamefilename
Returns
cr_NEVRA

◆ cr_str_to_evr()

cr_EVR * cr_str_to_evr ( const char * string,
GStringChunk * chunk )

Convert epoch-version-release string into cr_EVR structure. If no GStringChunk passed, all non NULL items in returned structure are malloced and in that case, you have to free all non-NULL element yourself.

Parameters
stringNULL terminated n-v-r string
chunkstring chunk for strings (optional - could be NULL)
Returns
filled NVR

◆ cr_str_to_nevr()

cr_NEVR * cr_str_to_nevr ( const char * str)

Parse E:N-V-R or N-V-R:E or N-E:V-R string

Parameters
strNEVR string
Returns
Malloced cr_NEVR or NULL on error

◆ cr_str_to_nevra()

cr_NEVRA * cr_str_to_nevra ( const char * str)

Parse E:N-V-R.A, N-V-R:E.A, N-E:V-R.A or N-V-R.A:E string.

Parameters
strNEVRA string
Returns
Malloced cr_NEVRA or NULL on error

◆ cr_str_to_version()

struct cr_Version cr_str_to_version ( const char * str)

Convert version string into cr_Version struct.

Parameters
strversion string
Returns
cr_Version

◆ cr_version_string_with_features()

const gchar * cr_version_string_with_features ( void )

Return string with createrepo_c lib version and available features

Returns
String with version and list of features

◆ cr_warning_cb()

int cr_warning_cb ( cr_XmlParserWarningType type,
char * msg,
void * cbdata,
GError ** err )

Warning callback for xml parser warnings. For use in xml parsers like primary, filelists, other or repomd parser. Name of the parser should be passed as a string via warning callback data (warningcb_data) argument of the parser.

◆ cr_write_to_file()

gboolean cr_write_to_file ( GError ** err,
gchar * filename,
const char * format,
... )

Open file and write content.

Parameters
errGError **
filenameFilename
formatFormat string
...Arguments