diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fs.c | 2 | ||||
-rw-r--r-- | src/install.c | 36 | ||||
-rw-r--r-- | src/internal_cmd.c | 3 | ||||
-rw-r--r-- | src/mime.c | 15 | ||||
-rw-r--r-- | src/relocation.c | 2 | ||||
-rw-r--r-- | src/rpath.c | 8 | ||||
-rw-r--r-- | src/spm.c | 2 |
7 files changed, 59 insertions, 9 deletions
@@ -294,7 +294,7 @@ int rsync(const char *_args, const char *_source, const char *_destination) { strcat(args_combined, _args); } - snprintf(cmd, PATH_MAX, "rsync %s \"%s\" \"%s\"", args_combined, source, destination); + snprintf(cmd, PATH_MAX, "rsync %s \"%s\" \"%s\" 2>&1", args_combined, source, destination); // sanitize command strchrdel(cmd, "&;|"); shell(&proc, SHELL_OUTPUT, cmd); diff --git a/src/install.c b/src/install.c index 7d41b36..1aee09b 100644 --- a/src/install.c +++ b/src/install.c @@ -54,6 +54,9 @@ int install(const char *destroot, const char *_package) { } if (exists(destroot) != 0) { + if (SPM_GLOBAL.verbose) { + printf("Creating destination root: %s\n", destroot); + } if (mkdirs(destroot, 0755) != 0) { fprintf(SYSERROR); return -2; @@ -76,6 +79,15 @@ int install(const char *destroot, const char *_package) { // Create a new temporary directory and extract the requested package into it char *tmpdir = mkdtemp(template); + if (exists(tmpdir) != 0) { + fprintf(stderr, "Failed to create temporary storage directory\n"); + fprintf(SYSERROR); + exit(errno); + } + + if (SPM_GLOBAL.verbose) { + printf("Extracting archive: %s\n", package); + } tar_extract_archive(package, tmpdir); getcwd(cwd, sizeof(cwd)); @@ -85,9 +97,18 @@ int install(const char *destroot, const char *_package) { chdir(tmpdir); { // Rewrite binary prefixes - b_record= prefixes_read(SPM_META_PREFIX_BIN); + b_record = prefixes_read(SPM_META_PREFIX_BIN); if (b_record) { for (int i = 0; b_record[i] != NULL; i++) { + if (file_is_binexec(b_record[i]->path)) { + if (SPM_GLOBAL.verbose) { + printf("Relocate RPATH: %s\n", b_record[i]->path); + } + rpath_autoset(b_record[i]->path); + } + if (SPM_GLOBAL.verbose) { + printf("Relocate DATA : %s\n", b_record[i]->path); + } relocate(b_record[i]->path, b_record[i]->prefix, destroot); } } @@ -96,6 +117,9 @@ int install(const char *destroot, const char *_package) { t_record = prefixes_read(SPM_META_PREFIX_TEXT); if (t_record) { for (int i = 0; t_record[i] != NULL; i++) { + if (SPM_GLOBAL.verbose) { + printf("Relocate TEXT : %s\n", t_record[i]->path); + } file_replace_text(t_record[i]->path, t_record[i]->prefix, destroot); } } @@ -109,12 +133,22 @@ int install(const char *destroot, const char *_package) { sprintf(source, "%s%c", tmpdir, DIRSEP); // Remove metadata files before copying + if (SPM_GLOBAL.verbose) { + printf("Removing metadata\n"); + } metadata_remove(source); // Copy temporary directory to destination + if (SPM_GLOBAL.verbose) { + printf("Installing tree: '%s' => '%s'\n", source, destroot); + } if (rsync(NULL, source, destroot) != 0) { exit(1); } + + if (SPM_GLOBAL.verbose) { + printf("Removing temporary storage: '%s'\n", tmpdir); + } rmdirs(tmpdir); free(package); diff --git a/src/internal_cmd.c b/src/internal_cmd.c index 38456cf..3801fda 100644 --- a/src/internal_cmd.c +++ b/src/internal_cmd.c @@ -84,9 +84,6 @@ void rpath_set_interface_usage(void) { * @return */ int rpath_set_interface(int argc, char **argv) { - for (int i = 0; i < argc; i++) { - printf("argv[%d] = %s\n", i, argv[i]); - } if (argc < 3) { rpath_set_interface_usage(); return -1; @@ -2,6 +2,7 @@ * @file mime.c */ #include "spm.h" +#include <fnmatch.h> /** * Execute OS `file` command @@ -16,7 +17,7 @@ Process *file_command(const char *_filename) { #ifdef __APPLE__ const char *fmt_cmd = "file -I \"%s\""; #else // GNU - const char *fmt_cmd = "file -E -i \"%s\""; + const char *fmt_cmd = "file -E -i \"%s\" 2>&1"; #endif strchrdel(filename, "&;|"); @@ -121,4 +122,16 @@ int file_is_binary(const char *filename) { free(path); mime_free(type); return result; +} + +int file_is_binexec(const char *filename) { + int result = 0; + char *path = normpath(filename); + Mime *type = file_mimetype(path); + if (fnmatch("application/*executable", type->type, FNM_PATHNAME) != FNM_NOMATCH && strcmp(type->charset, "binary") == 0) { + result = 1; + } + free(path); + mime_free(type); + return result; }
\ No newline at end of file diff --git a/src/relocation.c b/src/relocation.c index 9d627e4..473624a 100644 --- a/src/relocation.c +++ b/src/relocation.c @@ -297,7 +297,7 @@ int relocate(const char *_filename, const char *_oldstr, const char *_newstr) { char cmd[PATH_MAX]; memset(cmd, '\0', sizeof(cmd)); - sprintf(cmd, "reloc \"%s\" \"%s\" \"%s\" \"%s\"", oldstr, newstr, filename, filename); + sprintf(cmd, "reloc \"%s\" \"%s\" \"%s\" \"%s\" 2>&1", oldstr, newstr, filename, filename); // sanitize command strchrdel(cmd, "&;|"); diff --git a/src/rpath.c b/src/rpath.c index 8953716..1412130 100644 --- a/src/rpath.c +++ b/src/rpath.c @@ -18,7 +18,7 @@ Process *patchelf(const char *_filename, const char *_args) { strchrdel(args, "&;|"); strchrdel(filename, "&;|"); - sprintf(sh_cmd, "patchelf %s %s", args, filename); + sprintf(sh_cmd, "patchelf %s %s 2>&1", args, filename); shell(&proc_info, SHELL_OUTPUT, sh_cmd); @@ -90,6 +90,11 @@ char *rpath_get(const char *_filename) { strchrdel(path, "&;|"); Process *pe = patchelf(filename, "--print-rpath"); + if (pe->returncode != 0) { + fprintf(stderr, "patchelf error: %s %s\n", path, strip(pe->output)); + return NULL; + } + rpath = (char *)calloc(strlen(pe->output) + 1, sizeof(char)); if (!rpath) { free(filename); @@ -97,6 +102,7 @@ char *rpath_get(const char *_filename) { shell_free(pe); return NULL; } + strncpy(rpath, pe->output, strlen(pe->output)); strip(rpath); @@ -198,7 +198,7 @@ int main(int argc, char *argv[]) { } } - if (deps) { + if (deps->records) { // List requirements before installation for (size_t i = 0; i < deps->records; i++) { printf(" -> %s\n", deps->list[i]); |