summaryrefslogtreecommitdiffstats
path: root/components/filesystem/public/interfaces/directory.mojom
blob: bd5aba4dceebf1c57dc3442452b8499d82d7c69e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module filesystem;

import "components/filesystem/public/interfaces/file.mojom";
import "components/filesystem/public/interfaces/types.mojom";

// This interface provides access to a directory in a "file system", providing
// operations such as creating/opening/removing/renaming files/directories
// within it. Note that all relative |path| arguments are relative to "this"
// directory (i.e., "this" directory functions as the current working directory
// for the various operations).
// TODO(vtl): Paths may be relative; should they allowed to be absolute?
// (Currently not.)
interface Directory {
  // Operations about "this" |Directory|:

  // Reads the contents of this directory.
  // TODO(vtl): Clarify error codes versus |directory_contents|.
  Read() => (FileError error, array<DirectoryEntry>? directory_contents);

  // Operations *in* "this" |Directory|:

  // Opens the file specified by |path| with the given |open_flags|. |file| is
  // optional, mainly for consistency with |OpenDirectory()| (but may be useful,
  // together with |kOpenFlagCreate|, for "touching" a file).
  OpenFile(string path, File&? file, uint32 open_flags)
      => (FileError error);

  // Opens the directory specified by |path|. |directory| is optional, so that
  // this may be used as a simple "mkdir()" with |kOpenFlagCreate|.
  OpenDirectory(string path,
                Directory&? directory,
                uint32 open_flags) => (FileError error);

  // Renames/moves the file/directory given by |path| to |new_path|.
  Rename(string path, string new_path) => (FileError error);

  // Deletes the given path, which may be a file or a directory (see
  // |kDeleteFlag...| for details).
  Delete(string path, uint32 delete_flags) => (FileError error);

  // Returns true if |path| exists.
  Exists(string path) => (FileError error, bool exists);

  // Returns true if |path| is writable.
  IsWritable(string path) => (FileError error, bool is_writable);

  // Opens a file descriptor on this directory and calls
  // fsync()/FlushFileBuffers().
  Flush() => (FileError error);

  // TODO(vtl): directory "streaming"?
  // TODO(vtl): "make root" (i.e., prevent cd-ing, etc., to parent); note that
  // this would require a much more complicated implementation (e.g., it needs
  // to be "inherited" by OpenDirectory(), and the enforcement needs to be valid
  // even if the opened directory is subsequently moved -- e.g., closer to the
  // "root")
  // TODO(vtl): Add a "watch"?
};