X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=dir.c;h=1c3c5015249e6ac0ed0461b49f6581aebc8701a3;hb=9800c0df412869c7949935b61581b9361fc49bd1;hp=acf1001c4f9dd51587e3b07e52d4101ff3f1cb66;hpb=7df437e56b5a2c5ec7140dd097b517563db4972c;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; +} +