aboutsummaryrefslogtreecommitdiffstats
path: root/src/filepath.c
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2015-05-06 00:52:27 +0200
committerTharre <tharre3@gmail.com>2015-05-24 22:15:09 +0200
commit4678d9630e9f95db9d06d3423c539bcb0bcc722c (patch)
tree92e1bb6d73eddc027436276454560fb709ad3c1f /src/filepath.c
parent3d7bf2600524bf988362859ddd92556baf4e7e2f (diff)
downloadredo-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.
Diffstat (limited to 'src/filepath.c')
-rw-r--r--src/filepath.c55
1 files changed, 12 insertions, 43 deletions
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 = '/';
}
}