summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b9b378a)
raw | patch | inline | side by side (parent: b9b378a)
author | Alex Riesen <raa.lkml@gmail.com> | |
Fri, 26 Sep 2008 22:56:46 +0000 (00:56 +0200) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Mon, 29 Sep 2008 15:37:07 +0000 (08:37 -0700) |
The function has two potential users which both managed to get wrong
their implementations (the one in builtin-rm.c one has a memleak, and
builtin-merge-recursive.c scribles over its const argument).
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
their implementations (the one in builtin-rm.c one has a memleak, and
builtin-merge-recursive.c scribles over its const argument).
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
dir.c | patch | blob | history | |
dir.h | patch | blob | history |
index 109e05b01346ac13296dfbcfa2355a43d97731cd..cfaa28ff23acb462aa0cfd54a405316320ec3bc8 100644 (file)
--- a/dir.c
+++ b/dir.c
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;
+}
+
index 2df15defb6720a742282f24721233c4816deceb6..278ee42295ed3724801d56eb65c86b29002486aa 100644 (file)
--- a/dir.h
+++ b/dir.h
extern void setup_standard_excludes(struct dir_struct *dir);
extern int remove_dir_recursively(struct strbuf *path, int only_empty);
+/* tries to remove the path with empty directories along it, ignores ENOENT */
+extern int remove_path(const char *path);
+
#endif