blob: 32256504cbf0994db76905ba24618971eae4e6f2 [file] [log] [blame]
// 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.
[DartPackage="mojo_services"]
module mojo.files;
import "files/public/interfaces/file.mojom";
import "files/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() => (Error error, array<DirectoryEntry>? directory_contents);
// Gets information about this directory. On success, |file_information| is
// non-null and will contain this information.
Stat() => (Error error, FileInformation? file_information);
// Updates this directory's atime and/or mtime to the time specified by
// |atime| (or |mtime|, respectively), which may also indicate "now". If
// |atime| or |mtime| is null, then the corresponding time is not modified.
Touch(TimespecOrNow? atime, TimespecOrNow? mtime) => (Error error);
// 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)
=> (Error 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) => (Error error);
// Renames/moves the file/directory given by |path| to |new_path|.
Rename(string path, string new_path) => (Error error);
// Deletes the given path, which may be a file or a directory (see
// |kDeleteFlag...| for details).
Delete(string path, uint32 delete_flags) => (Error 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"?
// TODO(vtl): Should we have a "close" method?
// TODO(vtl): Add Dup() and Reopen() (like File)?
};