archives: move archive module to lib

archive is independent from swupd specific code, so move it to lib/

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
Otavio Pontes
2019-04-10 16:52:19 -07:00
parent d9dedbac91
commit cd3831c696
8 changed files with 31 additions and 13 deletions
+2 -1
View File
@@ -34,7 +34,8 @@ AM_CPPFLAGS = $(AM_CFLAGS) $(libarchive_CFLAGS)
swupd_SOURCES = \
src/alias.c \
src/alias.h \
src/archives.c \
src/lib/archives.c \
src/lib/archives.h \
src/autoupdate.c \
src/binary_loader.c \
src/bundle.c \
+1 -1
View File
@@ -314,7 +314,7 @@ int verify_bundle_hash(struct manifest *manifest, struct file *bundle)
char *outputdir;
string_or_die(&outputdir, "%s/%i", state_dir, current->last_change);
ret = extract_to(filename, outputdir);
ret = archives_extract_to(filename, outputdir);
free_string(&outputdir);
free_string(&filename);
+1 -1
View File
@@ -1012,7 +1012,7 @@ int untar_full_download(void *data)
/* modern tar will automatically determine the compression type used */
char *outputdir;
string_or_die(&outputdir, "%s/staged", state_dir);
err = extract_to(tarfile, outputdir);
err = archives_extract_to(tarfile, outputdir);
free_string(&outputdir);
if (err) {
warn("ignoring tar extract failure for fullfile %s.tar (ret %d)\n",
+6 -6
View File
@@ -22,10 +22,14 @@
#include <archive.h>
#include <archive_entry.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include "swupd.h"
#include "archives.h"
#include "log.h"
#include "strings.h"
/* _archive_check_err(ar, ret)
*
@@ -83,11 +87,7 @@ static int copy_data(struct archive *ar, struct archive *aw)
return 0;
}
/* extract_to(tarfile, outputdir)
*
* Extracts tar archive tarfile to outputdir. Refuses to extract any object
* whose final location would be altered by a symlink on disk. */
int extract_to(const char *tarfile, const char *outputdir)
int archives_extract_to(const char *tarfile, const char *outputdir)
{
struct archive *a, *ext;
struct archive_entry *entry;
+18
View File
@@ -0,0 +1,18 @@
#ifndef __ARCHIVES__
#define __ARCHIVES__
#ifdef __cplusplus
extern "C" {
#endif
/*
* Extracts tar archive tarfile to outputdir. Refuses to extract any object
* whose final location would be altered by a symlink on disk.
*/
int archives_extract_to(const char *tarfile, const char *outputdir);
#ifdef __cplusplus
}
#endif
#endif
+1 -1
View File
@@ -241,7 +241,7 @@ static int retrieve_manifest(int previous_version, int version, char *component,
}
untar:
ret = extract_to(filename, dir);
ret = archives_extract_to(filename, dir);
if (ret != 0) {
goto out;
} else {
+1 -1
View File
@@ -58,7 +58,7 @@ static int finalize_pack_download(const char *module, int newversion, const char
int err;
info("\nExtracting %s pack for version %i\n", module, newversion);
err = extract_to(filename, state_dir);
err = archives_extract_to(filename, state_dir);
unlink(filename);
+1 -2
View File
@@ -18,6 +18,7 @@
#include "lib/progress.h"
#include "lib/strings.h"
#include "lib/sys.h"
#include "lib/archives.h"
#include "manifest.h"
#include "scripts.h"
#include "swupd_curl.h"
@@ -214,8 +215,6 @@ extern void link_submanifests(struct manifest *m1, struct manifest *m2, struct l
extern int get_value_from_path(char **contents, const char *path, bool is_abs_path);
extern int get_version_from_path(const char *abs_path);
extern int extract_to(const char *tarfile, const char *outputdir);
static inline int bsearch_file_helper(const void *A, const void *B)
{
struct file *key = (struct file *)A;