X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=dir.c;h=1c3c5015249e6ac0ed0461b49f6581aebc8701a3;hb=5e22e21769454857e00bc55be1f2eef8d873ba72;hp=acf1001c4f9dd51587e3b07e52d4101ff3f1cb66;hpb=ff1e8bfcd69e5e0ee1a3167e80ef75b611f72123;p=git.git diff --git a/dir.c b/dir.c index acf1001c4..1c3c50152 100644 --- a/dir.c +++ b/dir.c @@ -831,3 +831,23 @@ void setup_standard_excludes(struct dir_struct *dir) if (excludes_file && !access(excludes_file, R_OK)) add_excludes_from_file(dir, excludes_file); } + +int remove_path(const char *name) +{ + char *slash; + + if (unlink(name) && errno != ENOENT) + return -1; + + slash = strrchr(name, '/'); + if (slash) { + char *dirs = xstrdup(name); + slash = dirs + (slash - name); + do { + *slash = '\0'; + } while (rmdir(dirs) && (slash = strrchr(dirs, '/'))); + free(dirs); + } + return 0; +} +