Deprecation of pathlib.PurePath.is_reserved()

For reference these paths are invalid on macOS.

isreserved isn’t testing for “invalid” - invalid paths will raise an error every time they’re used.

The reserved names are specifically valid paths that mean something other than a regular user-created file, e.g. things like /proc.

isreserved() checks for invalid characters:

Sure, like nul on Windows.

By the way, did you check out @eryksun’s benchmark on my PR yet?

You should probably also stay out of /dev/**.

I remember some Linux systems that mounted a tmpfs at /dev/shm, so any program could reasonably use /dev/shm/whatever as a regular file in exactly the way one would use /tmp/whatever.

I’m not sure if any of those are still in use, but it’s probably enough reason not to make a hypothetical Linux isreserved function reject anything starting with /dev/.

Personally, I don’t think anything should be treated as reserved on Linux. There are many legitimate cases for interacting directly with files in /dev, /proc, /sys, etc. so I don’t think it would be very helpful to try and “block” them.


Equally, there are legitimate reasons to use the reserved names and path formats on Windows, which is why I argue nobody should be using this function to block anything in the first place.

In the context of an app that creates a zip file, not naming things nul is just as important as not naming them /proc/..., but ultimately the only tool that can protect the user is the one doing the extraction.[1] Thinking you can protect against issues ahead of time is never going to work.

But equally, if the intent is to warn, then you’d want to warn just as much about nul as /proc/.... So why not let ntpath and posixpath check for it, especially if there’s a clear emphasis on using the specific platform’s function?

  1. By doing a stat on the destination file, before and after creation, to ensure it is/going to be a regular file. ↩︎

1 Like

Is this everything now?

  • Embedded null
  • Too long file name: "a" * 256
  • Too long path: "a/" * 512
  • /proc/**
  • /dev/**

Start a new issue for Linux support and post a link here so anyone interested can join in.

@eryksun, are there also adjustments that need to be made to ntpath.isreserved()?

  • //./PIPE/**
  • //./MAILSLOT/**