1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 import "components/filesystem/public/interfaces/file.mojom";
8 import "components/filesystem/public/interfaces/types.mojom";
10 // This interface provides access to a directory in a "file system", providing
11 // operations such as creating/opening/removing/renaming files/directories
12 // within it. Note that all relative |path| arguments are relative to "this"
13 // directory (i.e., "this" directory functions as the current working directory
14 // for the various operations).
15 // TODO(vtl): Paths may be relative; should they allowed to be absolute?
18 // Operations about "this" |Directory|:
20 // Reads the contents of this directory.
21 // TODO(vtl): Clarify error codes versus |directory_contents|.
22 Read() => (FileError error, array<DirectoryEntry>? directory_contents);
24 // Operations *in* "this" |Directory|:
26 // Opens the file specified by |path| with the given |open_flags|. |file| is
27 // optional, mainly for consistency with |OpenDirectory()| (but may be useful,
28 // together with |kOpenFlagCreate|, for "touching" a file).
29 OpenFile(string path, File&? file, uint32 open_flags)
32 // Opens the directory specified by |path|. |directory| is optional, so that
33 // this may be used as a simple "mkdir()" with |kOpenFlagCreate|.
34 OpenDirectory(string path,
35 Directory&? directory,
36 uint32 open_flags) => (FileError error);
38 // Renames/moves the file/directory given by |path| to |new_path|.
39 Rename(string path, string new_path) => (FileError error);
41 // Deletes the given path, which may be a file or a directory (see
42 // |kDeleteFlag...| for details).
43 Delete(string path, uint32 delete_flags) => (FileError error);
45 // Returns true if |path| exists.
46 Exists(string path) => (FileError error, bool exists);
48 // Returns true if |path| is writable.
49 IsWritable(string path) => (FileError error, bool is_writable);
51 // Opens a file descriptor on this directory and calls
52 // fsync()/FlushFileBuffers().
53 Flush() => (FileError error);
55 // TODO(vtl): directory "streaming"?
56 // TODO(vtl): "make root" (i.e., prevent cd-ing, etc., to parent); note that
57 // this would require a much more complicated implementation (e.g., it needs
58 // to be "inherited" by OpenDirectory(), and the enforcement needs to be valid
59 // even if the opened directory is subsequently moved -- e.g., closer to the
61 // TODO(vtl): Add a "watch"?