summaryrefslogtreecommitdiff
path: root/chromium/components/filesystem/public/interfaces/directory.mojom
blob: 98a2b8c619c5723fbbad04266e2d8bda515f629a (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 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.mojom;

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

struct FileOpenDetails {
  string path;
  uint32 open_flags;
};

struct FileOpenResult {
  string path;
  FileError error;
  handle file_handle;
};

// 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|.
  [Sync]
  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).
  [Sync]
  OpenFile(string path, File&? file, uint32 open_flags)
      => (FileError error);

  // Opens the file specified by |path| with the given |open_flags|. Returns a
  // native file descriptor wrapped in a MojoHandle.
  [Sync]
  OpenFileHandle(string path, uint32 open_flags)
      => (FileError error, handle file_handle);

  // Like OpenFileHandle, but opens multiple files.
  [Sync]
  OpenFileHandles(array<FileOpenDetails> files)
      => (array<FileOpenResult> results);

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

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

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

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

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

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

  // Gets information about this file. On success, |file_information| is
  // non-null and will contain this information.
  [Sync]
  StatFile(string path) => (FileError error, FileInformation? file_information);

  // Creates a copy of this directory.
  Clone(Directory& directory);

  // Reads the contents of an entire file.
  ReadEntireFile(string path) => (FileError error, array<uint8> data);

  // Writes |data| to |path|, overwriting the file if it already exists.
  WriteFile(string path, array<uint8> data) => (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"?
};