-
Notifications
You must be signed in to change notification settings - Fork 5
[io_file] Add the ability to get file metadata on Windows. #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 53 commits
5db08c8
a6f5c1c
f89d063
0f81c95
ed98ec4
2dfc83b
8bf09fb
1dcd074
2877b5e
7e4717d
278de74
69490d5
9704766
36647c2
a363b49
305655c
88dc69e
647a6a5
f7c6d76
dd67782
9185690
a687b84
e3fc41a
309c186
2c51b7d
fa3e0a2
b287897
b88bfca
d14f1a9
4d8ccfd
1aeb152
4fd4da1
b6ffeff
8c95248
18e6f8b
186c228
7d11d36
90d4070
c878448
0188da6
ea0946f
e28568d
49cbe04
d614fad
a2cef78
3ecea3f
5ff9dea
8f85c57
86e013c
b3cea51
e59c2de
99cd5af
f5bbc52
217eb05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,22 @@ | |
import 'dart:convert'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:meta/meta.dart' show sealed; | ||
|
||
// TODO(brianquinlan): When we switch to using exception types outside of | ||
// `dart:io` then change the doc strings to use reference syntax rather than | ||
// code syntax e.g. `PathExistsException` => [PathExistsException]. | ||
|
||
/// Information about a directory, link, etc. stored in the [FileSystem]. | ||
abstract interface class Metadata { | ||
// TODO(brianquinlan): Document all public fields. | ||
|
||
bool get isFile; | ||
bool get isDirectory; | ||
bool get isLink; | ||
int get size; | ||
} | ||
|
||
/// The modes in which a File can be written. | ||
class WriteMode { | ||
/// Open the file for writing such that data can only be appended to the end | ||
|
@@ -34,26 +46,18 @@ class WriteMode { | |
} | ||
|
||
/// An abstract representation of a file system. | ||
base class FileSystem { | ||
/// Checks whether two paths refer to the same object in the file system. | ||
/// | ||
/// Throws `PathNotFoundException` if either path doesn't exist. | ||
/// | ||
/// Links are resolved before determining if the paths refer to the same | ||
/// object. Throws `PathNotFoundException` if either path requires resolving | ||
/// a broken link. | ||
bool same(String path1, String path2) { | ||
throw UnsupportedError('same'); | ||
} | ||
|
||
/// | ||
/// TODO(brianquinlan): Far now, this class is not meant to be implemented, | ||
/// extended outside of this package. Clarify somewhere that people implementing | ||
/// this class should reach out to be. | ||
@sealed | ||
abstract class FileSystem { | ||
/// Create a directory at the given path. | ||
/// | ||
/// If the directory already exists, then `PathExistsException` is thrown. | ||
/// | ||
/// If the parent path does not exist, then `PathNotFoundException` is thrown. | ||
void createDirectory(String path) { | ||
throw UnsupportedError('createDirectory'); | ||
} | ||
void createDirectory(String path); | ||
|
||
/// Creates a temporary directory and returns its path. | ||
/// | ||
|
@@ -82,9 +86,13 @@ base class FileSystem { | |
/// fileSystem.createTemporaryDirectory(prefix: 'myproject'); | ||
/// } | ||
/// ``` | ||
String createTemporaryDirectory({String? parent, String? prefix}) { | ||
throw UnsupportedError('createTemporaryDirectory'); | ||
} | ||
String createTemporaryDirectory({String? parent, String? prefix}); | ||
|
||
/// Metadata for the file system object at [path]. | ||
/// | ||
/// If `path` represents a symbolic link then metadata for the link is | ||
/// returned. | ||
Metadata metadata(String path); | ||
|
||
/// Deletes the directory at the given path. | ||
/// | ||
|
@@ -97,17 +105,13 @@ base class FileSystem { | |
/// - On Windows, if `path` is a symbolic link to a directory then the | ||
/// symbolic link is deleted. Otherwise, a `FileSystemException` is thrown. | ||
/// - On POSIX, a `FileSystemException` is thrown. | ||
void removeDirectory(String path) { | ||
throw UnsupportedError('removeDirectory'); | ||
} | ||
void removeDirectory(String path); | ||
|
||
/// Deletes the directory at the given path and its contents. | ||
/// | ||
/// If the directory (or its subdirectories) contains any symbolic links then | ||
/// those links are deleted but their targets are not. | ||
void removeDirectoryTree(String path) { | ||
throw UnsupportedError('removeDirectoryTree'); | ||
} | ||
void removeDirectoryTree(String path); | ||
|
||
/// Renames, and possibly moves a file system object from one path to another. | ||
/// | ||
|
@@ -125,14 +129,19 @@ base class FileSystem { | |
// If `newPath` identifies an existing file or link, that entity is removed | ||
// first. If `newPath` identifies an existing directory, the operation | ||
// fails and raises [PathExistsException]. | ||
void rename(String oldPath, String newPath) { | ||
throw UnsupportedError('rename'); | ||
} | ||
void rename(String oldPath, String newPath); | ||
|
||
/// Reads the entire file contents as a list of bytes. | ||
Uint8List readAsBytes(String path) { | ||
throw UnsupportedError('readAsBytes'); | ||
} | ||
Uint8List readAsBytes(String path); | ||
|
||
/// Checks whether two paths refer to the same object in the file system. | ||
/// | ||
/// Throws `PathNotFoundException` if either path doesn't exist. | ||
/// | ||
/// Links are resolved before determining if the paths refer to the same | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, since this is just a If it's a broken link, then there is no way to check if two paths refer to the same broken link, or different broken links. Or should we just stop when we reach a broken link, and if the other path doesn't reach the same broken link, it's not the same? (I guess you can always try to follow links maually if there is a way to get the target of a link.) Throwing an Exception that you can't test for first, means that all calls to this function need to wrap themselves in either a |
||
/// object. Throws `PathNotFoundException` if either path requires resolving | ||
/// a broken link. | ||
bool same(String path1, String path2); | ||
|
||
/// The directory path used to store temporary files. | ||
/// | ||
|
@@ -156,9 +165,7 @@ base class FileSystem { | |
String path, | ||
Uint8List data, [ | ||
WriteMode mode = WriteMode.failExisting, | ||
]) { | ||
throw UnsupportedError('writeAsBytes'); | ||
} | ||
]); | ||
|
||
/// Write the string to a file. | ||
/// | ||
|
@@ -177,7 +184,5 @@ base class FileSystem { | |
WriteMode mode = WriteMode.failExisting, | ||
Encoding encoding = utf8, | ||
String? lineTerminator, | ||
]) { | ||
throw UnsupportedError('writeAsString'); | ||
} | ||
]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(For future extension: The OSX file system has a hidden flag too, you can set it with
chflags hidden /path/to/folder/
. Not all tools recognize it - Finder does,ls
doesn't. It's from BSD, so other Unixes might have it too. We should probably support it if possible/reasonable.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, linux has a hidden flag too - it's just not used in many file systems. I plan on moving some of these attributes around when I do the POSIX stat implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the semantics probably are quite different it makes a lot of sense to not share the hidden flag between platforms though they are named the same...