Skip to content

os.mkfifo is not supported #999

Description

@legaul-cisco

Is your feature request related to a problem? Please describe.
No implementation for os.mkfifo() (Unix only).

Describe the solution you'd like
Add implementation so that real FIFOs don't get created in the filesystem.

Describe alternatives you've considered
Currently requires additional mocking.

Need to add something like the following to FakeOsModule in fake_os.py:

    def mkfifo(
        self,
        path: AnyStr,
        mode: int = PERM_DEF_FILE,
        *,
        dir_fd: Optional[int] = None,
    ) -> None:
        """Create a FIFO (a named pipe) named 'path'.

        Args:
            path: (str) Name of the file to create.
            mode: (int) Permissions to use and type of file to be created.
                Default permissions are 0o666.  The umask is applied to this
                mode.
            dir_fd: If not `None`, the file descriptor of a directory,
                with `path` being relative to this directory.

        Raises:
            OSError: If called with unsupported options or the file can not be
                created.
        """
        if self.filesystem.is_windows_fs:
            raise AttributeError("module 'os' has no attribute 'mkfifo'")

        path = self._path_with_dir_fd(path, self.mkfifo, dir_fd)
        head, tail = self.path.split(path)
        if not tail:
            if self.filesystem.exists(head, check_link=True):
                self.filesystem.raise_os_error(errno.EEXIST, path)
            self.filesystem.raise_os_error(errno.ENOENT, path)
        if tail in (matching_string(tail, "."), matching_string(tail, "..")):
            self.filesystem.raise_os_error(errno.ENOENT, path)
        if self.filesystem.exists(path, check_link=True):
            self.filesystem.raise_os_error(errno.EEXIST, path)
        self.filesystem.add_object(
            head,
            FakeFile(tail, mode & ~self.filesystem.umask, filesystem=self.filesystem),
        )

However, in using a regular file object in the example above, this doesn't simulate the semantics of a FIFO. Could also take inspiration from os.pipe(), except os.mkfifo() doesn't actually open fds, it just creates the entry in the filesystem - maybe create a FakeFIFO object in the filesystem which would then presumably need to handle open/read/write differently.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions