diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/archive.c | 2 | ||||
-rw-r--r-- | src/config_global.c | 21 | ||||
-rw-r--r-- | src/install.c | 8 | ||||
-rw-r--r-- | src/manifest.c | 48 |
4 files changed, 39 insertions, 40 deletions
diff --git a/src/archive.c b/src/archive.c index d5c0118..d964469 100644 --- a/src/archive.c +++ b/src/archive.c @@ -37,7 +37,7 @@ int tar_extract_file(const char *_archive, const char* _filename, const char *_d sprintf(cmd, "tar xf \"%s\" -C \"%s\" \"%s\" 2>&1", archive, destination, filename); if (exists(archive) != 0) { - fprintf(stderr, "%s :: ", archive); + fprintf(stderr, "unable to find archive: %s\n", archive); fprintf(SYSERROR); return -1; } diff --git a/src/config_global.c b/src/config_global.c index c4e4dc8..9032fda 100644 --- a/src/config_global.c +++ b/src/config_global.c @@ -56,9 +56,9 @@ char *get_user_config_file(void) { * @return */ char *get_user_tmp_dir(void) { - char template[PATH_MAX]; + char *template = NULL; char *ucd = get_user_conf_dir(); - sprintf(template, "%s%c%s", ucd, DIRSEP, "tmp"); + template = join_ex(DIRSEPS, ucd, "tmp", NULL); if (access(template, F_OK) != 0) { if (mkdirs(template, 0755) != 0) { @@ -67,7 +67,7 @@ char *get_user_tmp_dir(void) { } free(ucd); - return strdup(template); + return template; } /** @@ -75,9 +75,10 @@ char *get_user_tmp_dir(void) { * @return */ char *get_user_package_dir(void) { - char template[PATH_MAX]; + char *template = NULL; char *ucd = get_user_conf_dir(); - sprintf(template, "%s%c%s", ucd, DIRSEP, "pkgs"); + + template = join_ex(DIRSEPS, ucd, "pkgs", SPM_GLOBAL.repo_target, NULL); if (access(template, F_OK) != 0) { if (mkdirs(template, 0755) != 0) { @@ -86,7 +87,7 @@ char *get_user_package_dir(void) { } free(ucd); - return strdup(template); + return template; } /** @@ -101,7 +102,7 @@ char *get_package_manifest(void) { //free(ucd); //return strdup(template); - template = join_ex(DIRSEPS, SPM_GLOBAL.package_dir, SPM_GLOBAL.repo_target, SPM_MANIFEST_FILENAME, NULL); + template = join_ex(DIRSEPS, SPM_GLOBAL.package_dir, SPM_MANIFEST_FILENAME, NULL); if (access(template, F_OK) != 0) { fprintf(stderr, "Package manifest not found: %s\n", template); manifest = manifest_from(PKG_DIR); @@ -273,7 +274,11 @@ void init_config_global(void) { // Initialize package directory item = config_get(SPM_GLOBAL.config, "package_dir"); if (item) { - SPM_GLOBAL.package_dir = strdup(item->value); + SPM_GLOBAL.package_dir = calloc(PATH_MAX, sizeof(char)); //strdup(item->value); + strncpy(SPM_GLOBAL.package_dir, item->value, PATH_MAX - 1); + strcat(SPM_GLOBAL.package_dir, DIRSEPS); + strcat(SPM_GLOBAL.package_dir, SPM_GLOBAL.repo_target); + if (access(SPM_GLOBAL.package_dir, F_OK) != 0) { if (mkdirs(SPM_GLOBAL.package_dir, 0755) != 0) { fprintf(stderr, "Unable to create global package directory: %s\n", SPM_GLOBAL.package_dir); diff --git a/src/install.c b/src/install.c index ebbab4a..5e39890 100644 --- a/src/install.c +++ b/src/install.c @@ -148,7 +148,7 @@ char *spm_install_fetch(const char *pkgdir, const char *_package) { size_t tmp_package_len = strlen(payload); if (tmp_package_len > strlen(package)) { - char *tmp = realloc(package, (strlen(package) + 1) * sizeof(char)); + char *tmp = realloc(package, (strlen(tmp_package_len) + 1) * sizeof(char)); if (tmp == NULL) { perror("cannot realloc package path"); return NULL; @@ -180,7 +180,7 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { size_t num_requirements = 0; ManifestPackage **requirements = NULL; char source[PATH_MAX]; - char *tmpdir = spm_mkdtemp("spm_destroot"); + char *tmpdir = spm_mkdtemp("spm_destroot", NULL); if (tmpdir == NULL) { perror("Could not create temporary destination root"); @@ -223,7 +223,7 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { } int fetched = 0; - char *package_dir = join_ex(DIRSEPS, SPM_GLOBAL.package_dir, SPM_GLOBAL.repo_target, NULL); + char *package_dir = strdup(SPM_GLOBAL.package_dir); for (size_t i = 0; requirements != NULL && requirements[i] != NULL; i++) { char *package_path = join((char *[]) {requirements[i]->origin, SPM_GLOBAL.repo_target, requirements[i]->archive, NULL}, DIRSEPS); char *package_localpath = join_ex(DIRSEPS, package_dir, requirements[i]->archive, NULL); @@ -233,6 +233,8 @@ int spm_do_install(SPM_Hierarchy *fs, ManifestList *mf, StrList *packages) { printf("Fetching: %s\n", package_path); package_path = spm_install_fetch(package_dir, package_path); if (package_path == NULL) { + free(package_path); + free(package_localpath); exit(1); } fetched = 1; diff --git a/src/manifest.c b/src/manifest.c index 9ea7db4..f384e8c 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -54,17 +54,9 @@ void manifest_package_separator_restore(char **name) { */ Manifest *manifest_from(const char *package_dir) { char *package_filter[] = {SPM_PACKAGE_EXTENSION, NULL}; // We only want packages - char *template = NULL; FSTree *fsdata = NULL; fsdata = fstree(package_dir, package_filter, SPM_FSTREE_FLT_ENDSWITH); - template = join((char *[]) {TMP_DIR, "spm_manifest_from_XXXXXX", NULL}, DIRSEPS); - if (!template) { - perror("Failed to allocate template string"); - fprintf(SYSERROR); - return NULL; - } - Manifest *info = (Manifest *)calloc(1, sizeof(Manifest)); info->records = fsdata->files_length; info->packages = (ManifestPackage **) calloc(info->records + 1, sizeof(ManifestPackage *)); @@ -82,9 +74,9 @@ Manifest *manifest_from(const char *package_dir) { strncpy(info->origin, package_dir, SPM_PACKAGE_MEMBER_ORIGIN_SIZE); - char *tmpdir = mkdtemp(template); - if (exists(tmpdir) != 0) { - perror("temporary directory creation failed"); + char *tmpdir = spm_mkdtemp("spm_manifest_from", NULL); + if (!tmpdir) { + perror("failed to create temporary directory"); fprintf(SYSERROR); free(info); fstree_free(fsdata); @@ -105,6 +97,7 @@ Manifest *manifest_from(const char *package_dir) { fprintf(SYSERROR); fstree_free(fsdata); free(info); + rmdirs(tmpdir); return NULL; } @@ -130,7 +123,7 @@ Manifest *manifest_from(const char *package_dir) { strdelsuffix(info->packages[i]->revision, SPM_PACKAGE_EXTENSION); // Read package requirement specs - char *archive = join((char *[]) {info->origin, SPM_GLOBAL.repo_target, info->packages[i]->archive, NULL}, DIRSEPS); + char *archive = join((char *[]) {info->origin, info->packages[i]->archive, NULL}, DIRSEPS); if (tar_extract_file(archive, SPM_META_DEPENDS, tmpdir) != 0) { // TODO: at this point is the package is invalid? .SPM_DEPENDS should be there... fprintf(stderr, "extraction failure: %s\n", archive); @@ -206,11 +199,12 @@ int manifest_write(Manifest *info, const char *pkgdir) { strcpy(path_manifest, path); // Append the manifest filename if its missing - if (endswith(path_manifest, SPM_MANIFEST_FILENAME) != 0) { + if (!endswith(path_manifest, SPM_MANIFEST_FILENAME)) { strcat(path_manifest, DIRSEPS); strcat(path_manifest, SPM_MANIFEST_FILENAME); } + char *asdfasd = path_manifest; FILE *fp = fopen(path_manifest, "w+"); #ifdef _DEBUG if (SPM_GLOBAL.verbose) { @@ -383,31 +377,29 @@ Manifest *manifest_read(char *file_or_url) { strcpy(path, SPM_GLOBAL.package_dir); } else { - char *template = join((char *[]) {TMP_DIR, "spm_manifest_read_XXXXXX", NULL}, DIRSEPS); - tmpdir = mkdtemp(template); + tmpdir = spm_mkdtemp("spm_manifest_read_XXXXXX", SPM_GLOBAL.repo_target); if (exists(tmpdir) != 0) { fprintf(stderr, "Failed to create temporary storage directory\n"); fprintf(SYSERROR); return NULL; } - snprintf(pathptr, PATH_MAX - 1, "%s%c%s", template, DIRSEP, filename); - //strncpy(pathptr, template, PATH_MAX - 1); + snprintf(pathptr, PATH_MAX - 1, "%s%s%s%s%s", tmpdir, DIRSEPS, SPM_GLOBAL.repo_target, DIRSEPS, filename); } - // Handle receiving a path without the manifest filename - // by appending the manifest to the path - /* - if (startswith(path, "http") != 0 && endswith(path, filename) != 0) { - strcat(path, DIRSEPS); - strcat(path, filename); + const char *target_is; + if (strstr(file_or_url, SPM_GLOBAL.repo_target) != NULL) { + target_is = ""; + } + else { + target_is = SPM_GLOBAL.repo_target; } - */ - char *remote_manifest = join((char *[]) {file_or_url, SPM_GLOBAL.repo_target, filename, NULL}, DIRSEPS); - if (exists(path) != 0) { + char *remote_manifest = join_ex(DIRSEPS, file_or_url, target_is, filename, NULL); + + if (exists(pathptr) != 0) { // TODO: Move this out - int fetch_status = fetch(remote_manifest, path); + int fetch_status = fetch(remote_manifest, pathptr); if (fetch_status >= 400) { fprintf(stderr, "HTTP %d: %s: %s\n", fetch_status, http_response_str(fetch_status), remote_manifest); free(remote_manifest); @@ -425,7 +417,7 @@ Manifest *manifest_read(char *file_or_url) { char *dptr = data; memset(dptr, '\0', BUFSIZ); - fp = fopen(path, "r+"); + fp = fopen(pathptr, "r+"); if (!fp) { perror(filename); fprintf(SYSERROR); |