commit 946136f3d256f3fa3611ba24287b440c53b69390 from: Omar Polo date: Sun Dec 26 20:20:00 2021 UTC fix tremove wrt directories we can't call unlinkat with `.' as path, so the hackish solution (but also the only viable one I can see) is to unlinkat ../. Furthermore, calling unlinkat(f->dir->fd, f->fpath) was incorrect because f->dir->fd already points to the directory. commit - c7f4e1bdfe5b7c7a55f9c97c6098cd057643288b commit + 946136f3d256f3fa3611ba24287b440c53b69390 blob - ed67c148460e58993c335528368deb8e2b17052a blob + d3484c718bade31e04b234150c8dd206f4ac75d2 --- client.c +++ client.c @@ -1522,6 +1522,7 @@ tremove(struct np_msg_header *hdr, const uint8_t *data struct fid *f; uint32_t fid; int r; + char dirpath[PATH_MAX + 3]; /* fid[4] */ if (!NPREAD32("fid", &fid, &data, &len)) { @@ -1535,10 +1536,12 @@ tremove(struct np_msg_header *hdr, const uint8_t *data return; } - if (f->fd == -1 || f->d == NULL) /* unlink file */ + if (f->qid.type & QTDIR) { /* directory */ + strlcpy(dirpath, "../", sizeof(dirpath)); + strlcat(dirpath, f->fpath, sizeof(dirpath)); + r = unlinkat(f->dir->fd, dirpath, AT_REMOVEDIR); + } else /* file */ r = unlinkat(f->dir->fd, f->fpath, 0); - else /* directory */ - r = unlinkat(f->dir->fd, f->fpath, AT_REMOVEDIR); if (r == -1) np_errno(hdr->tag);