From: Joel Rosdahl Date: Thu, 14 Jul 2011 17:57:33 +0000 (+0200) Subject: config: Use cache_dir from conf struct X-Git-Tag: v3.2~240 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e0b674ea9e4d23e85f8f85e3f8757aeca1e4830;p=thirdparty%2Fccache.git config: Use cache_dir from conf struct --- diff --git a/ccache.c b/ccache.c index e143eb159..212155c6a 100644 --- a/ccache.c +++ b/ccache.c @@ -76,9 +76,6 @@ struct conf *conf = NULL; /* current working directory taken from $PWD, or getcwd() if $PWD is bad */ char *current_working_dir = NULL; -/* the base cache directory */ -char *cache_dir = NULL; - /* the debug logfile name, if set */ char *cache_logfile = NULL; @@ -156,7 +153,7 @@ static char *cpp_stderr; /* * Full path to the statistics file in the subdirectory where the cached result - * belongs (CCACHE_DIR/X/stats). + * belongs (//stats). */ char *stats_file = NULL; @@ -287,7 +284,7 @@ temp_dir() if (path) return path; /* Memoize */ path = getenv("CCACHE_TEMPDIR"); if (!path) { - path = format("%s/tmp", cache_dir); + path = format("%s/tmp", conf->cache_dir); } return path; } @@ -303,7 +300,7 @@ get_path_in_cache(const char *name, const char *suffix) char *path; char *result; - path = x_strdup(cache_dir); + path = x_strdup(conf->cache_dir); for (i = 0; i < nlevels; ++i) { char *p = format("%s/%c", path, name[i]); free(path); @@ -719,9 +716,9 @@ to_cache(struct args *args) * This can be almost anywhere, but might as well do it near the end * as if we exit early we save the stat call */ - if (create_cachedirtag(cache_dir) != 0) { + if (create_cachedirtag(conf->cache_dir) != 0) { cc_log("Failed to create %s/CACHEDIR.TAG (%s)\n", - cache_dir, strerror(errno)); + conf->cache_dir, strerror(errno)); stats_update(STATS_ERROR); failed(); } @@ -861,7 +858,7 @@ update_cached_result_globals(struct file_hash *hash) cached_obj = get_path_in_cache(object_name, ".o"); cached_stderr = get_path_in_cache(object_name, ".stderr"); cached_dep = get_path_in_cache(object_name, ".d"); - stats_file = format("%s/%c/stats", cache_dir, object_name[0]); + stats_file = format("%s/%c/stats", conf->cache_dir, object_name[0]); free(object_name); } @@ -1867,15 +1864,6 @@ initialize(void) } current_working_dir = get_cwd(); - cache_dir = getenv("CCACHE_DIR"); - if (cache_dir) { - cache_dir = x_strdup(cache_dir); - } else { - const char *home_directory = get_home_directory(); - if (home_directory) { - cache_dir = format("%s/.ccache", home_directory); - } - } } /* Reset the global state. Used by the test suite. */ @@ -1884,7 +1872,6 @@ cc_reset(void) { conf_free(conf); conf = NULL; free(current_working_dir); current_working_dir = NULL; - free(cache_dir); cache_dir = NULL; cache_logfile = NULL; args_free(orig_args); orig_args = NULL; free(input_file); input_file = NULL; @@ -2163,13 +2150,13 @@ ccache_main_options(int argc, char *argv[]) case 'c': /* --cleanup */ initialize(); - cleanup_all(cache_dir); + cleanup_all(conf->cache_dir); printf("Cleaned cache\n"); break; case 'C': /* --clear */ initialize(); - wipe_all(cache_dir); + wipe_all(conf->cache_dir); printf("Cleared cache\n"); break; diff --git a/stats.c b/stats.c index d023ae4c8..511456900 100644 --- a/stats.c +++ b/stats.c @@ -23,6 +23,7 @@ */ #include "ccache.h" +#include "conf.h" #include "hashutil.h" #include @@ -34,7 +35,7 @@ #include extern char *stats_file; -extern char *cache_dir; +extern struct conf *conf; extern unsigned lock_staleness_limit; static struct counters *counter_updates; @@ -224,8 +225,7 @@ stats_flush(void) * A NULL stats_file means that we didn't get past calculate_object_hash(), * so we just choose one of stats files in the 16 subdirectories. */ - if (!cache_dir) return; - stats_dir = format("%s/%x", cache_dir, hash_from_int(getpid()) % 16); + stats_dir = format("%s/%x", conf->cache_dir, hash_from_int(getpid()) % 16); stats_file = format("%s/stats", stats_dir); free(stats_dir); } @@ -295,9 +295,9 @@ stats_summary(void) char *fname; if (dir == -1) { - fname = format("%s/stats", cache_dir); + fname = format("%s/stats", conf->cache_dir); } else { - fname = format("%s/%1x/stats", cache_dir, dir); + fname = format("%s/%1x/stats", conf->cache_dir, dir); } stats_read(fname, counters); @@ -309,7 +309,7 @@ stats_summary(void) } } - printf("cache directory %s\n", cache_dir); + printf("cache directory %s\n", conf->cache_dir); /* and display them */ for (i = 0; stats_info[i].message; i++) { @@ -339,13 +339,13 @@ stats_zero(void) unsigned i; char *fname; - fname = format("%s/stats", cache_dir); + fname = format("%s/stats", conf->cache_dir); x_unlink(fname); free(fname); for (dir = 0; dir <= 0xF; dir++) { struct counters *counters = counters_init(STATS_END); - fname = format("%s/%1x/stats", cache_dir, dir); + fname = format("%s/%1x/stats", conf->cache_dir, dir); if (lockfile_acquire(fname, lock_staleness_limit)) { stats_read(fname, counters); for (i = 0; stats_info[i].message; i++) { @@ -391,7 +391,7 @@ stats_set_limits(long maxfiles, long maxsize) for (dir = 0; dir <= 0xF; dir++) { char *fname, *cdir; - cdir = format("%s/%1x", cache_dir, dir); + cdir = format("%s/%1x", conf->cache_dir, dir); fname = format("%s/stats", cdir); free(cdir);