Path functions confined to one file system

If new directory scanning options are added, would it be possible to design them so that they, or rmtree(), can eventually implement the equivalent of rm --one-file-system?

Many dir-traversing UNIX utilities support --one-file-system, such as rm, du, find, rsync.
It prevents against accidentally traversing into mounts, which is a useful protection; almost as useful as the symlink attack protection provided by dir_fd based functions.

It’s implemented by comparing stat().st_dev.

But in Python this is not currently implementable, because deletion requires e.g. topdown=False in os.walk(), which then forbids filtering traversing into directories.

3 Likes