diff options
| -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)  | 
