diff options
author | Tharre <tharre3@gmail.com> | 2015-05-06 00:52:27 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2015-05-24 22:15:09 +0200 |
commit | 4678d9630e9f95db9d06d3423c539bcb0bcc722c (patch) | |
tree | 92e1bb6d73eddc027436276454560fb709ad3c1f | |
parent | 3d7bf2600524bf988362859ddd92556baf4e7e2f (diff) | |
download | redo-4678d9630e9f95db9d06d3423c539bcb0bcc722c.tar.gz redo-4678d9630e9f95db9d06d3423c539bcb0bcc722c.tar.xz redo-4678d9630e9f95db9d06d3423c539bcb0bcc722c.zip |
Use full path instead of one concatenated filename
Creation of the redo store (.redo/) is now silent, that should probably be
reimplemented in a better way at a later time.
-rw-r--r-- | src/build.c | 13 | ||||
-rw-r--r-- | src/filepath.c | 55 | ||||
-rw-r--r-- | src/filepath.h | 3 | ||||
-rw-r--r-- | src/redo.c | 4 |
4 files changed, 23 insertions, 52 deletions
diff --git a/src/build.c b/src/build.c index b74c4fd..479b6a0 100644 --- a/src/build.c +++ b/src/build.c @@ -319,11 +319,18 @@ static char *get_relpath(const char *target) { static char *get_dep_path(const char *target) { char *root = getenv("REDO_ROOT"); char *reltarget = get_relpath(target); - char *xtarget = transform_path(reltarget); - char *dep_path = concat(3, root, "/.redo/deps/", xtarget); + char *dep_path; + + if (is_absolute(reltarget)) { + dep_path = concat(3, root, "/.redo/abs/", reltarget); + } else { + dep_path = concat(3, root, "/.redo/rel/", reltarget); + } + + /* create directory */ + mkpath(dep_path, 0755); /* TODO: should probably be somewhere else */ free(reltarget); - free(xtarget); return dep_path; } diff --git a/src/filepath.c b/src/filepath.c index e4d8e62..349b525 100644 --- a/src/filepath.c +++ b/src/filepath.c @@ -82,28 +82,6 @@ char *relpath(char *path, char *start) { return &path[i]; } -/* Transforms target into a safe filename, replacing all '/' with '!'. */ -char *transform_path(const char *target) { - char *ptr = (char*) target; - size_t escape = 0, i = 0; - while (*ptr++) - if (*ptr == '!') escape++; - - ptr = xmalloc((ptr-target) + escape + 1); - do { - if (*target == '/') - ptr[i++] = '!'; - else if (*target == '!') { - ptr[i++] = '!'; - ptr[i++] = '!'; - } else - ptr[i++] = *target; - } while (*target++); - - ptr[i] = '\0'; - return ptr; -} - /* Sane and portable basename implementation. */ char *xbasename(const char *path) { assert(path); @@ -134,26 +112,17 @@ off_t fsize(const char *fn) { return st.st_size; } -/* Create the directory dir, while removing other 'files' with the same name. - Returns true if the directory had to be created or false if it existed */ -// TODO: fix confusing name -bool mkdirp(const char *dir) { - struct stat st; - if (stat(dir, &st)) { - /* dir doesn't exist or stat failed */ - if (errno != ENOENT) - fatal("redo: failed to aquire stat() information about %s", dir); - if (mkdir(dir, 0755)) - fatal("redo: failed to mkdir() '%s'", dir); - return 1; - } else { - if (!S_ISDIR(st.st_mode)) { - if (remove(dir)) - fatal("redo: failed to remove %s", dir); - if (mkdir(dir, 0755)) - fatal("redo: failed to mkdir() '%s'", dir); - return 1; - } - return 0; +/* Create the target directory recursively much like `mkdir -p` */ +void mkpath(char *path, mode_t mode) { + assert(path && *path); + char *p; + + for (p=strchr(path+1, '/'); p; p=strchr(p+1, '/')) { + *p = '\0'; + if (mkdir(path, mode) == -1) + if (errno != EEXIST) + fatal("redo: failed to mkdir() '%s'", path); + + *p = '/'; } } diff --git a/src/filepath.h b/src/filepath.h index 68a4ecf..2735e45 100644 --- a/src/filepath.h +++ b/src/filepath.h @@ -15,10 +15,9 @@ extern bool is_absolute(const char* path); extern char *remove_ext(const char *str); extern char *take_extension(const char *target); extern char *relpath(char *path, char *start); -extern char *transform_path(const char *target); extern char *xbasename(const char *path); extern bool fexists(const char *target); extern off_t fsize(const char *fn); -extern bool mkdirp(const char *dir); +extern void mkpath(char *path, mode_t mode); #endif @@ -31,10 +31,6 @@ void prepare_env() { && getenv("REDO_MAGIC")) return; - /* create the dependency store if it doesn't already exist */ - if (mkdirp(".redo") && mkdirp(".redo/deps")) - fprintf(stderr, "redo: creating dependency store ...\n"); - /* set REDO_ROOT */ char *cwd = getcwd(NULL, 0); if (!cwd) |