X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=dir.c;h=0131983dfbc143ce5dae77e067663bb2e7d5f126;hb=6e13921b4f7adcc7316a76c0c4955b85b1589a65;hp=acf1001c4f9dd51587e3b07e52d4101ff3f1cb66;hpb=578421fbd8db6602f290862f44843fc896b4fb0b;p=git.git diff --git a/dir.c b/dir.c index acf1001c4..0131983df 100644 --- a/dir.c +++ b/dir.c @@ -382,7 +382,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len) return ent; } -struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len) +static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len) { if (cache_name_exists(pathname, len, ignore_case)) return NULL; @@ -391,7 +391,7 @@ struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int return dir->entries[dir->nr++] = dir_entry_new(pathname, len); } -struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len) +static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len) { if (cache_name_pos(pathname, len) >= 0) return NULL; @@ -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; +} +