From: Christian Weisgerber Subject: Re: non-const dirname To: gameoftrees@openbsd.org Date: Tue, 20 Oct 2020 14:57:22 -0000 On 2020-10-20, Stefan Sperling wrote: > This patch should make got and tog work with non-const dirname(3). > Switch path comparisons from strcmp() to got_path_cmp() in order to > treat paths such as "foo//bar" and "foo/bar" as equal. It also treats "/foo/bar" and "foo/bar" as equal. Could that be a problem? > --- lib/worktree.c > +++ lib/worktree.c > @@ -2018,16 +2047,22 @@ remove_ondisk_file(const char *root_path, const char * > if (errno != ENOENT) > err = got_error_from_errno2("unlink", ondisk_path); > } else { > - char *parent = dirname(ondisk_path); > - while (parent && strcmp(parent, root_path) != 0) { > - if (rmdir(parent) == -1) { > + size_t root_len = strlen(root_path); > + do { > + char *parent; > + err = got_path_dirname(&parent, ondisk_path); > + if (err) > + return err; > + free(ondisk_path); The free() needs to move up, otherwise there's a leak on error. > @@ -3877,25 +3914,22 @@ schedule_for_deletion(void *arg, unsigned char status, > goto done; > } > > - parent = dirname(ondisk_path); > - > - if (parent == NULL) { > - err = got_error_from_errno2("dirname", ondisk_path); > - goto done; > - } > - while (parent && strcmp(parent, a->worktree->root_path) != 0) { > - if (rmdir(parent) == -1) { > + root_len = strlen(a->worktree->root_path); > + do { > + char *parent; > + err = got_path_dirname(&parent, ondisk_path); > + if (err) > + return err; > + free(ondisk_path); Same here. -- Christian "naddy" Weisgerber naddy@mips.inka.de