diff --git a/Makefile.am b/Makefile.am index 55b7db4e..8ba4202c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/hash.c b/src/hash.c index b24bd9cc..434dbad9 100644 --- a/src/hash.c +++ b/src/hash.c @@ -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); diff --git a/src/helpers.c b/src/helpers.c index 89ce3194..c4050636 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -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", diff --git a/src/archives.c b/src/lib/archives.c similarity index 95% rename from src/archives.c rename to src/lib/archives.c index d2b03e42..d92b8f2d 100644 --- a/src/archives.c +++ b/src/lib/archives.c @@ -22,10 +22,14 @@ #include #include +#include #include +#include #include -#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; diff --git a/src/lib/archives.h b/src/lib/archives.h new file mode 100644 index 00000000..26551614 --- /dev/null +++ b/src/lib/archives.h @@ -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 diff --git a/src/manifest.c b/src/manifest.c index 007911ca..b5b162ef 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -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 { diff --git a/src/packs.c b/src/packs.c index 933915d5..9e7ae4b4 100644 --- a/src/packs.c +++ b/src/packs.c @@ -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); diff --git a/src/swupd.h b/src/swupd.h index f1010f01..dc1c65ba 100644 --- a/src/swupd.h +++ b/src/swupd.h @@ -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;