| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 module filesystem; | 5 module filesystem; |
| 6 | 6 |
| 7 import "components/filesystem/public/interfaces/file.mojom"; | 7 import "components/filesystem/public/interfaces/file.mojom"; |
| 8 import "components/filesystem/public/interfaces/types.mojom"; | 8 import "components/filesystem/public/interfaces/types.mojom"; |
| 9 | 9 |
| 10 // This interface provides access to a directory in a "file system", providing | 10 // This interface provides access to a directory in a "file system", providing |
| 11 // operations such as creating/opening/removing/renaming files/directories | 11 // operations such as creating/opening/removing/renaming files/directories |
| 12 // within it. Note that all relative |path| arguments are relative to "this" | 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 | 13 // directory (i.e., "this" directory functions as the current working directory |
| 14 // for the various operations). | 14 // for the various operations). |
| 15 // TODO(vtl): Paths may be relative; should they allowed to be absolute? | 15 // TODO(vtl): Paths may be relative; should they allowed to be absolute? |
| 16 // (Currently not.) | 16 // (Currently not.) |
| 17 interface Directory { | 17 interface Directory { |
| 18 // Operations about "this" |Directory|: | 18 // Operations about "this" |Directory|: |
| 19 | 19 |
| 20 // Reads the contents of this directory. | 20 // Reads the contents of this directory. |
| 21 // TODO(vtl): Clarify error codes versus |directory_contents|. | 21 // TODO(vtl): Clarify error codes versus |directory_contents|. |
| 22 [Sync] |
| 22 Read() => (FileError error, array<DirectoryEntry>? directory_contents); | 23 Read() => (FileError error, array<DirectoryEntry>? directory_contents); |
| 23 | 24 |
| 24 // Operations *in* "this" |Directory|: | 25 // Operations *in* "this" |Directory|: |
| 25 | 26 |
| 26 // Opens the file specified by |path| with the given |open_flags|. |file| is | 27 // 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 // optional, mainly for consistency with |OpenDirectory()| (but may be useful, |
| 28 // together with |kOpenFlagCreate|, for "touching" a file). | 29 // together with |kOpenFlagCreate|, for "touching" a file). |
| 30 [Sync] |
| 29 OpenFile(string path, File&? file, uint32 open_flags) | 31 OpenFile(string path, File&? file, uint32 open_flags) |
| 30 => (FileError error); | 32 => (FileError error); |
| 31 | 33 |
| 32 // Opens the file specified by |path| with the given |open_flags|. Returns a | 34 // Opens the file specified by |path| with the given |open_flags|. Returns a |
| 33 // native file descriptor wrapped in a MojoHandle. | 35 // native file descriptor wrapped in a MojoHandle. |
| 36 [Sync] |
| 34 OpenFileHandle(string path, uint32 open_flags) | 37 OpenFileHandle(string path, uint32 open_flags) |
| 35 => (FileError error, handle file_handle); | 38 => (FileError error, handle file_handle); |
| 36 | 39 |
| 37 // Opens the directory specified by |path|. |directory| is optional, so that | 40 // Opens the directory specified by |path|. |directory| is optional, so that |
| 38 // this may be used as a simple "mkdir()" with |kOpenFlagCreate|. | 41 // this may be used as a simple "mkdir()" with |kOpenFlagCreate|. |
| 42 [Sync] |
| 39 OpenDirectory(string path, | 43 OpenDirectory(string path, |
| 40 Directory&? directory, | 44 Directory&? directory, |
| 41 uint32 open_flags) => (FileError error); | 45 uint32 open_flags) => (FileError error); |
| 42 | 46 |
| 43 // Renames/moves the file/directory given by |path| to |new_path|. | 47 // Renames/moves the file/directory given by |path| to |new_path|. |
| 48 [Sync] |
| 44 Rename(string path, string new_path) => (FileError error); | 49 Rename(string path, string new_path) => (FileError error); |
| 45 | 50 |
| 46 // Deletes the given path, which may be a file or a directory (see | 51 // Deletes the given path, which may be a file or a directory (see |
| 47 // |kDeleteFlag...| for details). | 52 // |kDeleteFlag...| for details). |
| 53 [Sync] |
| 48 Delete(string path, uint32 delete_flags) => (FileError error); | 54 Delete(string path, uint32 delete_flags) => (FileError error); |
| 49 | 55 |
| 50 // Returns true if |path| exists. | 56 // Returns true if |path| exists. |
| 57 [Sync] |
| 51 Exists(string path) => (FileError error, bool exists); | 58 Exists(string path) => (FileError error, bool exists); |
| 52 | 59 |
| 53 // Returns true if |path| is writable. | 60 // Returns true if |path| is writable. |
| 61 [Sync] |
| 54 IsWritable(string path) => (FileError error, bool is_writable); | 62 IsWritable(string path) => (FileError error, bool is_writable); |
| 55 | 63 |
| 56 // Opens a file descriptor on this directory and calls | 64 // Opens a file descriptor on this directory and calls |
| 57 // fsync()/FlushFileBuffers(). | 65 // fsync()/FlushFileBuffers(). |
| 66 [Sync] |
| 58 Flush() => (FileError error); | 67 Flush() => (FileError error); |
| 59 | 68 |
| 60 // Gets information about this file. On success, |file_information| is | 69 // Gets information about this file. On success, |file_information| is |
| 61 // non-null and will contain this information. | 70 // non-null and will contain this information. |
| 71 [Sync] |
| 62 StatFile(string path) => (FileError error, FileInformation? file_information); | 72 StatFile(string path) => (FileError error, FileInformation? file_information); |
| 63 | 73 |
| 64 // Reads the contents of an entire file. | 74 // Reads the contents of an entire file. |
| 65 ReadEntireFile(string path) => (FileError error, array<uint8> data); | 75 ReadEntireFile(string path) => (FileError error, array<uint8> data); |
| 66 | 76 |
| 67 // Writes |data| to |path|, overwriting the file if it already exists. | 77 // Writes |data| to |path|, overwriting the file if it already exists. |
| 68 WriteFile(string path, array<uint8> data) => (FileError error); | 78 WriteFile(string path, array<uint8> data) => (FileError error); |
| 69 | 79 |
| 70 // TODO(vtl): directory "streaming"? | 80 // TODO(vtl): directory "streaming"? |
| 71 // TODO(vtl): "make root" (i.e., prevent cd-ing, etc., to parent); note that | 81 // TODO(vtl): "make root" (i.e., prevent cd-ing, etc., to parent); note that |
| 72 // this would require a much more complicated implementation (e.g., it needs | 82 // this would require a much more complicated implementation (e.g., it needs |
| 73 // to be "inherited" by OpenDirectory(), and the enforcement needs to be valid | 83 // to be "inherited" by OpenDirectory(), and the enforcement needs to be valid |
| 74 // even if the opened directory is subsequently moved -- e.g., closer to the | 84 // even if the opened directory is subsequently moved -- e.g., closer to the |
| 75 // "root") | 85 // "root") |
| 76 // TODO(vtl): Add a "watch"? | 86 // TODO(vtl): Add a "watch"? |
| 77 }; | 87 }; |
| OLD | NEW |