diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.c | 14 | ||||
-rw-r--r-- | lib/install.c | 2 | ||||
-rw-r--r-- | lib/manifest.c | 4 |
3 files changed, 14 insertions, 6 deletions
@@ -576,19 +576,27 @@ char *human_readable_size(uint64_t n) { /** * Create a named temporary directory - * @param name + * @param base path where temporary directory will be created + * @param name name of temporary directory + * @param extended_path a subdirectory to create beneath `base/name`, may be NULL * @return success=path, failure=NULL */ -char *spm_mkdtemp(const char *name, const char *extended_path) { +char *spm_mkdtemp(const char *base, const char *name, const char *extended_path) { const char *template_unique = "XXXXXX"; char *tmpdir = NULL; char template[PATH_MAX]; - sprintf(template, "%s%s%s_%s", TMP_DIR, DIRSEPS, name, template_unique); + if (base == NULL || name == NULL) { // extended_path is optional + return NULL; + } + + sprintf(template, "%s%s%s_%s", base, DIRSEPS, name, template_unique); tmpdir = mkdtemp(template); + if (tmpdir == NULL) { return NULL; } + if (extended_path != NULL) { char extended[PATH_MAX] = {0,}; strncpy(extended, tmpdir, PATH_MAX - 1); diff --git a/lib/install.c b/lib/install.c index e0592db..c6e12ca 100644 --- a/lib/install.c +++ b/lib/install.c @@ -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", NULL); + char *tmpdir = spm_mkdtemp(TMP_DIR, "spm_destroot", NULL); if (tmpdir == NULL) { perror("Could not create temporary destination root"); diff --git a/lib/manifest.c b/lib/manifest.c index 2d306e7..a95b566 100644 --- a/lib/manifest.c +++ b/lib/manifest.c @@ -75,7 +75,7 @@ Manifest *manifest_from(const char *package_dir) { strncpy(info->origin, package_dir, SPM_PACKAGE_MEMBER_ORIGIN_SIZE); - char *tmpdir = spm_mkdtemp("spm_manifest_from", NULL); + char *tmpdir = spm_mkdtemp(TMP_DIR, "spm_manifest_from", NULL); if (!tmpdir) { perror("failed to create temporary directory"); fprintf(SYSERROR); @@ -390,7 +390,7 @@ Manifest *manifest_read(char *file_or_url) { strcpy(path, SPM_GLOBAL.package_dir); } else { - tmpdir = spm_mkdtemp("spm_manifest_read_XXXXXX", SPM_GLOBAL.repo_target); + tmpdir = spm_mkdtemp(TMP_DIR, "spm_manifest_read_XXXXXX", SPM_GLOBAL.repo_target); if (exists(tmpdir) != 0) { fprintf(stderr, "Failed to create temporary storage directory\n"); fprintf(SYSERROR); |