Date: Sat, 28 Oct 2006 20:00:39 GMT From: Yar Tikhiy <yar@comp.chem.msu.su> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/104458: fts(3) can't handle very deep trees Message-ID: <200610282000.k9SK0d1q076904@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/104458; it has been noted by GNATS. From: Yar Tikhiy <yar@comp.chem.msu.su> To: Bruce Evans <bde@zeta.org.au> Cc: Yar Tikhiy <yar@comp.chem.msu.su> Subject: Re: bin/104458: fts(3) can't handle very deep trees Date: Mon, 16 Oct 2006 19:38:08 +0400 Realized that there is a bug in the algo :-) On Mon, Oct 16, 2006 at 07:11:02PM +0400, Yar Tikhiy wrote: > > At least in the rm case, we are limited only by the number of files > we cannot delete IMHO. Assume we can delete everything in a tree: > no restrictive permissions, no immutable flags, etc. Then we can > traverse and remove it with the following algo, which utilizes FS > as the storage of all its state: > > /* > * removes everything in and under current directory > */ > stat(".", &st0); > again: > dp = opendir("."); > while (ep = readdir(dp)) { > /* skip . and .. here */ > stat(ep->d_name, &st); > if (S_ISDIR(st.st_mode)) { > if (rmdir(ep->d_name) == -1) { /* ENOTEMPTY */ > chdir(ep->d_name); > closedir(dp); > goto again; > } > } else > unlink(ep->d_name); > } > /* we arrive here only after we deleted all in . */ closedir(dp); > stat(".", &st); > if (st.st_dev == st0.st_dev && st.st_ino == st0.st_ino) > return; > chdir(".."); > goto again; > > Real life dictates that we should handle failures to delete something. > This can be done by keeping a list (or hash) of unremovable files > identified by st_dev and st_ino of the parent directory and the name > of the file itself. Then we can skip over them in the readdir loop > so that we don't loop forever. But all this means farewell to fts(3). -- Yar
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610282000.k9SK0d1q076904>