diff --git a/main.c b/main.c index 394f2b9..7e31d40 100644 --- a/main.c +++ b/main.c @@ -1730,6 +1730,7 @@ start_compress(const char *filename, uint64_t chunksize, int level) /* A host of sanity checks. */ if (!pipe_mode) { + char *tmp; if ((uncompfd = open(filename, O_RDWR, 0)) == -1) err_exit(1, "Cannot open: %s", filename); @@ -1786,7 +1787,13 @@ start_compress(const char *filename, uint64_t chunksize, int level) */ strcpy(tmpfile1, filename); strcpy(tmpfile1, dirname(tmpfile1)); - strcpy(tmpdir, tmpfile1); + + tmp = getenv("PCOMPRESS_CACHE_DIR"); + if (tmp == NULL || !chk_dir(tmp)) { + strcpy(tmpdir, tmpfile1); + } else { + strcpy(tmpdir, tmp); + } strcat(tmpfile1, "/.pcompXXXXXX"); snprintf(to_filename, sizeof (to_filename), "%s" COMP_EXTN, filename); if ((compfd = mkstemp(tmpfile1)) == -1) { @@ -1798,7 +1805,6 @@ start_compress(const char *filename, uint64_t chunksize, int level) signal(SIGTERM, Int_Handler); } else { char *tmp; - struct stat st; /* * Use stdin/stdout for pipe mode. @@ -1817,29 +1823,20 @@ start_compress(const char *filename, uint64_t chunksize, int level) /* * Get a workable temporary dir. Required if global dedupe is enabled. */ - tmp = getenv("TMPDIR"); - if (tmp == NULL) { - tmp = getenv("HOME"); - if (tmp == NULL) { - if (getcwd(tmpdir, MAXPATHLEN) == NULL) { - tmp = "/tmp"; - } else { - tmp = tmpdir; + tmp = getenv("PCOMPRESS_CACHE_DIR"); + if (tmp == NULL || !chk_dir(tmp)) { + tmp = getenv("TMPDIR"); + if (tmp == NULL || !chk_dir(tmp)) { + tmp = getenv("HOME"); + if (tmp == NULL || !chk_dir(tmp)) { + if (getcwd(tmpdir, MAXPATHLEN) == NULL) { + tmp = "/tmp"; + } else { + tmp = tmpdir; + } } } } - if (stat(tmp, &st) == -1) { - fprintf(stderr, "Unable to find writable temporary dir.\n"); - COMP_BAIL; - } - if (!S_ISDIR(st.st_mode)) { - if (strcmp(tmp, "/tmp") != 0) { - tmp = "/tmp"; - } else { - fprintf(stderr, "Unable to find writable temporary dir.\n"); - COMP_BAIL; - } - } strcpy(tmpdir, tmp); } diff --git a/rabin/global/dedupe_config.c b/rabin/global/dedupe_config.c index f537378..707f3c5 100644 --- a/rabin/global/dedupe_config.c +++ b/rabin/global/dedupe_config.c @@ -382,7 +382,6 @@ set_config_s(archive_config_t *cfg, const char *algo, cksum_t ck, cksum_t ck_sim } cfg->segment_sz = cfg->segment_sz_bytes / cfg->chunk_sz_bytes; - return (0); } diff --git a/rabin/global/index.c b/rabin/global/index.c index 9a96357..5babaef 100644 --- a/rabin/global/index.c +++ b/rabin/global/index.c @@ -181,8 +181,8 @@ set_cfg: *memreqd = MEM_REQD(*hash_slots, *hash_entry_size); /* - * If memory required is more than twice the indicated memory limit then - * we switch to Segmented Cumulative Similarity based dedupe. + * If memory required is more than thrice the indicated memory limit then + * we switch to Segmented Similarity based dedupe. */ if (*memreqd > (memlimit * 3) && cfg->dedupe_mode == MODE_SIMPLE && *pct_interval == 0 && tmppath != NULL) { diff --git a/utils/utils.c b/utils/utils.c index 074ed77..fb8a190 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -24,6 +24,7 @@ */ #include +#include #include #include #include @@ -406,3 +407,17 @@ get_sys_limits(my_sysinfo *msys_info) msys_info->freeram = (msys_info->freeram >> 1) + (msys_info->freeram >> 2); } } + +int +chk_dir(char *dir) +{ + struct stat st; + + if (stat(dir, &st) == -1) { + return (0); + } + if (!S_ISDIR(st.st_mode)) { + return (0); + } + return (1); +} diff --git a/utils/utils.h b/utils/utils.h index e9c0924..a22092e 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -219,6 +219,7 @@ extern uint64_t get_total_ram(); extern double get_wtime_millis(void); extern double get_mb_s(uint64_t bytes, double strt, double en); extern void get_sys_limits(my_sysinfo *msys_info); +extern int chk_dir(char *dir); extern void init_algo_props(algo_props_t *props); extern void init_pcompress();