aboutsummaryrefslogtreecommitdiff
path: root/src/archive.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2020-03-18 22:25:27 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2020-03-18 22:25:27 -0400
commitccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8 (patch)
treeae167772a9a2343aa77bf8944b56abe853f6a2ec /src/archive.c
parent3731bb4679ee8716d4f579d5744c36a2d1b4a257 (diff)
downloadspmc-ccaeb7092b5ad40b1b3833c987ba3ec4d47f0bb8.tar.gz
Refactor project: build/install libspm[_static.a].so to make unit testing possible
Diffstat (limited to 'src/archive.c')
-rw-r--r--src/archive.c110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/archive.c b/src/archive.c
deleted file mode 100644
index d964469..0000000
--- a/src/archive.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/**
- * @file archive.c
- */
-#include "spm.h"
-
-/**
- * Extract a single file from a tar archive into a directory
- *
- * @param archive path to tar archive
- * @param filename known path inside the archive to extract
- * @param destination where to extract file to (must exist)
- * @return
- */
-int tar_extract_file(const char *_archive, const char* _filename, const char *_destination) {
- Process *proc = NULL;
- int status;
- char cmd[PATH_MAX];
- char *archive = strdup(_archive);
- if (!archive) {
- fprintf(SYSERROR);
- return -1;
- }
- char *filename = strdup(_filename);
- if (!filename) {
- fprintf(SYSERROR);
- return -1;
- }
- char *destination = strdup(_destination);
- if (!destination) {
- fprintf(SYSERROR);
- return -1;
- }
-
- strchrdel(archive, SHELL_INVALID);
- strchrdel(destination, SHELL_INVALID);
- strchrdel(filename, SHELL_INVALID);
-
- sprintf(cmd, "tar xf \"%s\" -C \"%s\" \"%s\" 2>&1", archive, destination, filename);
- if (exists(archive) != 0) {
- fprintf(stderr, "unable to find archive: %s\n", archive);
- fprintf(SYSERROR);
- return -1;
- }
-
- shell(&proc, SHELL_OUTPUT, cmd);
- if (!proc) {
- fprintf(SYSERROR);
- return -1;
- }
-
- status = proc->returncode;
- if (status != 0) {
- fprintf(stderr, "%s\n", proc->output);
- }
-
- shell_free(proc);
- free(archive);
- free(filename);
- free(destination);
- return status;
-}
-
-/**
- *
- * @param _archive
- * @param _destination
- * @return
- */
-int tar_extract_archive(const char *_archive, const char *_destination) {
- Process *proc = NULL;
- int status;
- char cmd[PATH_MAX];
-
- if (exists(_archive) != 0) {
- //fprintf(SYSERROR);
- return -1;
- }
-
- char *archive = strdup(_archive);
- if (!archive) {
- fprintf(SYSERROR);
- return -1;
- }
- char *destination = strdup(_destination);
- if (!destination) {
- fprintf(SYSERROR);
- return -1;
- }
-
- // sanitize archive
- strchrdel(archive, SHELL_INVALID);
- // sanitize destination
- strchrdel(destination, SHELL_INVALID);
-
- sprintf(cmd, "tar xf %s -C %s 2>&1", archive, destination);
- shell(&proc, SHELL_OUTPUT, cmd);
- if (!proc) {
- fprintf(SYSERROR);
- free(archive);
- free(destination);
- return -1;
- }
-
- status = proc->returncode;
- shell_free(proc);
- free(archive);
- free(destination);
- return status;
-}
-