Expresso.PrivateDir (expresso v0.1.0)

Copy Markdown View Source

Makes a new private directory in the temporary directory of the system

The watch mode and the browser levels of --check write a copy of the deck into such a directory. Many computers have one /tmp for all the users, so each directory obeys these rules:

  • The name is expresso-<kind>-<random>, and <random> has 26 random characters.
  • File.mkdir/1 makes the directory, so a directory or a symbolic link that is already there is an error. The function then tries a different name.
  • The mode of the directory is 0700, so no other user can read or write its files.

open!/1 also starts a small sh process that removes the directory when the process that owns it stops, and when the VM stops. Ctrl-C and SIGTERM halt the VM before an after block can run, but the operating system then closes the pipe to the sh process, and that process removes the directory. close/1 removes the directory at once.

Summary

Types

t()

A private directory, and the process that removes it

Functions

Remove the directory, and stop its sh process

Make a new directory with the mode 0700 in parent, and return its path

Make a new private directory, and remove it when the calling process stops

Types

t()

@type t() :: %Expresso.PrivateDir{guard: port() | nil, path: Path.t()}

A private directory, and the process that removes it

Functions

close(private_dir)

@spec close(t()) :: :ok

Remove the directory, and stop its sh process

create!(kind, parent, random \\ &random/0)

@spec create!(String.t(), Path.t(), (-> String.t())) :: Path.t()

Make a new directory with the mode 0700 in parent, and return its path

random returns the random part of each name that the function tries. The tests give a different function.

open!(kind)

@spec open!(String.t()) :: t()

Make a new private directory, and remove it when the calling process stops

The function raises when it cannot make the directory.