Records

Functions

  • std::string SimplifyPath (std::string path)

    Resolves ".." and "." components of the path syntactically without consulting

    the file system.

    Defined at line 73 of file ../../src/lib/files/path.cc

  • std::string GetCurrentDirectory ()

    Returns the current directory. If the current directory cannot be determined,

    this function will terminate the process.

    Defined at line 22 of file ../../src/lib/files/directory.cc

  • bool IsDirectory (const std::string & path)

    Returns whether the given path is a directory.

    Defined at line 31 of file ../../src/lib/files/directory.cc

  • bool WriteFile (const std::string & path, std::string_view data)

    Writes the given data to the file at the given path. Returns true if the data

    was successfully written, otherwise returns false.

    Defined at line 66 of file ../../src/lib/files/file.cc

  • std::string AbsolutePath (const std::string & path)

    Returns the absolute path of a possibly relative path.

    It doesn't consult the filesystem or simplify the path.

    Defined at line 171 of file ../../src/lib/files/path.cc

  • bool WriteFile (const std::string & path, const char * data, ssize_t size)

    Defined at line 70 of file ../../src/lib/files/file.cc

  • bool WriteFileAt (int dirfd, const std::string & path, const char * data, ssize_t size)

    Defined at line 74 of file ../../src/lib/files/file.cc

  • std::string GetDirectoryName (const std::string & path)

    Returns the directory name component of the given path.

    Defined at line 188 of file ../../src/lib/files/path.cc

  • bool IsDirectoryAt (int root_fd, const std::string & path)

    Returns whether the given path is a directory. If |path| is relative, resolve

    it with |root_fd| as reference. See |openat(2)|.

    Defined at line 33 of file ../../src/lib/files/directory.cc

  • std::string GetBaseName (const std::string & path)

    Returns the basename component of the given path by stripping everything up

    to and including the last slash.

    Defined at line 197 of file ../../src/lib/files/path.cc

  • bool CreateDirectory (const std::string & path)

    Create a directory at the given path. If necessary, creates any intermediary

    directory.

    Defined at line 40 of file ../../src/lib/files/directory.cc

  • bool CreateDirectoryAt (int root_fd, const std::string & path)

    Create a directory at the given path. If necessary, creates any intermediary

    directory. If |path| is relative, resolve it with |root_fd| as reference. See

    |openat(2)|.

    Defined at line 44 of file ../../src/lib/files/directory.cc

  • bool ReadDirContents (const std::string & path, std::vector<std::string> * out)

    List the contents of a directory. If returns false, errno will be set.

    Defined at line 72 of file ../../src/lib/files/directory.cc

  • bool IsValidName (std::string_view name)

    Returns true if |path| is a valid Fuchsia name per the fuchsia.io/Name rules:

    * It cannot be longer than [`MAX_NAME_LENGTH`] (255 bytes).

    * It cannot be empty.

    * It cannot be ".." (dot-dot).

    * It cannot be "." (single dot).

    * It cannot contain "/".

    * It cannot contain embedded NUL.

    Defined at line 204 of file ../../src/lib/files/path.cc

  • bool WriteFileInTwoPhases (int dirfd, const std::string & filename, std::string_view data)

    Atomically creates |filename| under |dirfd| with |data|.

    This is done by writing |data| to a temporary file named "<filename>.tmp" in

    |dirfd|, syncing the temporary file, renaming it to |filename|, and syncing

    |dirfd|. |dirfd| must be a valid open directory file descriptor (not

    AT_FDCWD), and |filename| must be a valid single-component filename (no '/').

    Returns true if the file was successfully written, otherwise returns false.

    Note that power failure after the temporary file is created, but before it is

    renamed, will result in "<filename>.tmp" existing in |dirfd|. A subsequent

    call for the same |filename| will overwrite and clean up the temporary file,

    but if this function is never called again for |filename|, the temporary file

    will remain. Callers must not invoke this concurrently with the same |dirfd|

    and |filename|.

    Defined at line 82 of file ../../src/lib/files/file.cc

  • bool ReadDirContentsAt (int root_fd, const std::string & path, std::vector<std::string> * out)

    List the contents of a directory. If returns false, errno will be set. If |path| is relative,

    resolve it with |root_fd| as reference. See |openat(2)|.

    Defined at line 76 of file ../../src/lib/files/directory.cc

  • bool ReadFileToString (const std::string & path, std::string * result)

    Reads the contents of the file at the given path or file descriptor and

    stores the data in result. Returns true if the file was read successfully,

    otherwise returns false. If this function returns false, |result| will be

    the empty string.

    Defined at line 118 of file ../../src/lib/files/file.cc

  • bool ReadFileDescriptorToString (int fd, std::string * result)

    Defined at line 122 of file ../../src/lib/files/file.cc

  • bool ReadFileToStringAt (int dirfd, const std::string & path, std::string * result)

    Defined at line 126 of file ../../src/lib/files/file.cc

  • bool IsValidCanonicalPath (std::string_view path)

    Returns true if |path| is a valid Fuchsia path in canonical form per the

    fuchsia.io/Path rules:

    * It cannot be empty.

    * It cannot be longer than [`MAX_PATH_LENGTH`] (4095 bytes).

    * It cannot have a leading "/".

    * It cannot have a trailing "/".

    * Each component must be a valid name. See |IsValidName|.

    Defined at line 229 of file ../../src/lib/files/path.cc

  • bool ReadFileToVector (const std::string & path, std::vector<uint8_t> * result)

    Reads the contents of the file at the given path or file descriptor and stores the data in

    result. Returns true if the file was read successfully, otherwise returns

    false. If this function returns false, |result| will be the empty string.

    Defined at line 131 of file ../../src/lib/files/file.cc

  • bool DeletePath (const std::string & path, bool recursive)

    Delete the file or directory at the given path. If recursive is true, and

    path is a directory, also delete the directory's content.

    Defined at line 268 of file ../../src/lib/files/path.cc

  • bool ReadFileDescriptorToVector (int fd, std::vector<uint8_t> * result)

    Defined at line 136 of file ../../src/lib/files/file.cc

  • bool ReadFileToVectorAt (int dirfd, const std::string & path, std::vector<uint8_t> * result)

    Defined at line 140 of file ../../src/lib/files/file.cc

  • bool IsFile (const std::string & path)

    Returns whether the given path is a file.

    Defined at line 145 of file ../../src/lib/files/file.cc

  • bool DeletePathAt (int root_fd, const std::string & path, bool recursive)

    Delete the file or directory at the given path. If recursive is true, and

    path is a directory, also delete the directory's content. If |path| is

    relative, resolve it with |root_fd| as reference. See |openat(2)|.

    Defined at line 272 of file ../../src/lib/files/path.cc

  • bool IsFileAt (int dirfd, const std::string & path)

    Defined at line 147 of file ../../src/lib/files/file.cc

  • bool GetFileSize (const std::string & path, uint64_t * size)

    If the given path is a file, set size to the size of the file.

    Defined at line 154 of file ../../src/lib/files/file.cc

  • bool GetFileSizeAt (int dirfd, const std::string & path, uint64_t * size)

    Defined at line 158 of file ../../src/lib/files/file.cc

  • std::string JoinPath (const std::string & path1, const std::string & path2)

    Joins two paths together.

    Regardless if |path1| has a trailing '/' or |path2| has a leading '/', there

    will be only one '/' in-between in the joined path.

    Note that if either path is "" then the other path is returned unchanged.

    JoinPath("/foo", "bar") -> "/foo/bar"

    JoinPath("/foo", "/bar") -> "/foo/bar"

    JoinPath("/foo/", "bar") -> "/foo/bar"

    JoinPath("/foo/", "/bar") -> "/foo/bar"

    JoinPath("", "") -> ""

    JoinPath("", "/foo") -> "/foo"

    JoinPath("", "foo") -> "foo"

    JoinPath("/foo", "") -> "/foo"

    JoinPath("foo", "") -> "foo"

    JoinPath("/foo/", "") -> "/foo/"

    JoinPath("foo/", "") -> "foo/"

    Defined at line 305 of file ../../src/lib/files/path.cc