Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 2.2.0

* Added `ErrorCodes` class, which holds errno values.

#### 2.1.0

* Add support for new `dart:io` API methods added in Dart SDK 1.23
Expand Down
20 changes: 10 additions & 10 deletions lib/src/backends/chroot/chroot_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
Future<Directory> rename(String newPath) async {
if (_isLink) {
if (await fileSystem.type(path) != expectedType) {
throw new FileSystemException('Not a directory', path);
throw common.notADirectory(path);
}
FileSystemEntityType type = await fileSystem.type(newPath);
if (type != FileSystemEntityType.NOT_FOUND) {
if (type != expectedType) {
throw new FileSystemException('Not a directory', newPath);
throw common.notADirectory(newPath);
}
if (!(await fileSystem
.directory(newPath)
.list(followLinks: false)
.isEmpty)) {
throw new FileSystemException('Directory not empty', newPath);
throw common.directoryNotEmpty(newPath);
}
}
String target = await fileSystem.link(path).target();
Expand All @@ -58,18 +58,18 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
Directory renameSync(String newPath) {
if (_isLink) {
if (fileSystem.typeSync(path) != expectedType) {
throw new FileSystemException('Not a directory', path);
throw common.notADirectory(path);
}
FileSystemEntityType type = fileSystem.typeSync(newPath);
if (type != FileSystemEntityType.NOT_FOUND) {
if (type != expectedType) {
throw new FileSystemException('Not a directory', newPath);
throw common.notADirectory(newPath);
}
if (fileSystem
.directory(newPath)
.listSync(followLinks: false)
.isNotEmpty) {
throw new FileSystemException('Directory not empty', newPath);
throw common.directoryNotEmpty(newPath);
}
}
String target = fileSystem.link(path).targetSync();
Expand Down Expand Up @@ -99,9 +99,9 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
if (_isLink) {
switch (await fileSystem.type(path)) {
case FileSystemEntityType.NOT_FOUND:
throw new FileSystemException('No such file or directory', path);
throw common.noSuchFileOrDirectory(path);
case FileSystemEntityType.FILE:
throw new FileSystemException('File exists', path);
throw common.fileExists(path);
case FileSystemEntityType.DIRECTORY:
// Nothing to do.
return this;
Expand All @@ -118,9 +118,9 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
if (_isLink) {
switch (fileSystem.typeSync(path)) {
case FileSystemEntityType.NOT_FOUND:
throw new FileSystemException('No such file or directory', path);
throw common.noSuchFileOrDirectory(path);
case FileSystemEntityType.FILE:
throw new FileSystemException('File exists', path);
throw common.fileExists(path);
case FileSystemEntityType.DIRECTORY:
// Nothing to do.
return;
Expand Down
16 changes: 8 additions & 8 deletions lib/src/backends/chroot/chroot_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
};
break;
case FileSystemEntityType.DIRECTORY:
throw new FileSystemException('Is a directory', newPath);
throw common.isADirectory(newPath);
default:
// Should never happen.
throw new AssertionError();
Expand All @@ -55,9 +55,9 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
if (_isLink) {
switch (await fileSystem.type(path)) {
case FileSystemEntityType.NOT_FOUND:
throw new FileSystemException('No such file or directory', path);
throw common.noSuchFileOrDirectory(path);
case FileSystemEntityType.DIRECTORY:
throw new FileSystemException('Is a directory', path);
throw common.isADirectory(path);
case FileSystemEntityType.FILE:
await setUp();
await fileSystem.delegate
Expand Down Expand Up @@ -94,7 +94,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
};
break;
case FileSystemEntityType.DIRECTORY:
throw new FileSystemException('Is a directory', newPath);
throw common.isADirectory(newPath);
default:
// Should never happen.
throw new AssertionError();
Expand All @@ -104,9 +104,9 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
if (_isLink) {
switch (fileSystem.typeSync(path)) {
case FileSystemEntityType.NOT_FOUND:
throw new FileSystemException('No such file or directory', path);
throw common.noSuchFileOrDirectory(path);
case FileSystemEntityType.DIRECTORY:
throw new FileSystemException('Is a directory', path);
throw common.isADirectory(path);
case FileSystemEntityType.FILE:
setUp();
fileSystem.delegate
Expand Down Expand Up @@ -149,7 +149,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
// Nothing to do.
return this;
case FileSystemEntityType.DIRECTORY:
throw new FileSystemException('Is a directory', path);
throw common.isADirectory(path);
default:
throw new AssertionError();
}
Expand Down Expand Up @@ -181,7 +181,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
// Nothing to do.
return;
case FileSystemEntityType.DIRECTORY:
throw new FileSystemException('Is a directory', path);
throw common.isADirectory(path);
default:
throw new AssertionError();
}
Expand Down
17 changes: 6 additions & 11 deletions lib/src/backends/chroot/chroot_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class ChrootFileSystem extends FileSystem {
case FileSystemEntityType.DIRECTORY:
break;
case FileSystemEntityType.NOT_FOUND:
throw new FileSystemException('No such file or directory');
throw common.noSuchFileOrDirectory(path);
default:
throw new FileSystemException('Not a directory');
throw common.notADirectory(path);
}
assert(() {
p.Context ctx = delegate.path;
Expand Down Expand Up @@ -299,7 +299,7 @@ class ChrootFileSystem extends FileSystem {
case FileSystemEntityType.FILE:
breadcrumbs.clear();
if (parts.isNotEmpty) {
throw new FileSystemException('Not a directory', currentPath);
throw common.notADirectory(currentPath);
}
break;
case FileSystemEntityType.NOT_FOUND:
Expand All @@ -308,10 +308,6 @@ class ChrootFileSystem extends FileSystem {
return getCurrentPath();
}

FileSystemException notFoundException() {
return new FileSystemException('No such file or directory', path);
}

switch (notFound) {
case _NotFoundBehavior.mkdir:
if (parts.isNotEmpty) {
Expand All @@ -324,18 +320,17 @@ class ChrootFileSystem extends FileSystem {
if (parts.isEmpty) {
return returnEarly();
}
throw notFoundException();
throw common.noSuchFileOrDirectory(path);
case _NotFoundBehavior.throwError:
throw notFoundException();
throw common.noSuchFileOrDirectory(path);
}
break;
case FileSystemEntityType.LINK:
if (parts.isEmpty && !followLinks) {
break;
}
if (!breadcrumbs.add(currentPath)) {
throw new FileSystemException(
'Too many levels of symbolic links', path);
throw common.tooManyLevelsOfSymbolicLinks(path);
}
String target = delegate.link(realPath).targetSync();
if (ctx.isAbsolute(target)) {
Expand Down
14 changes: 6 additions & 8 deletions lib/src/backends/chroot/chroot_file_system_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
String resolvedPath = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
if (!recursive && await type(resolvedPath) != expectedType) {
String msg = expectedType == FileSystemEntityType.FILE
? 'Is a directory'
: 'Not a directory';
throw new FileSystemException(msg, path);
throw expectedType == FileSystemEntityType.FILE
? common.isADirectory(path)
: common.notADirectory(path);
}
await fileSystem.delegate.link(real(path)).delete();
}
Expand All @@ -146,10 +145,9 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
String resolvedPath = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
if (!recursive && type(resolvedPath) != expectedType) {
String msg = expectedType == FileSystemEntityType.FILE
? 'Is a directory'
: 'Not a directory';
throw new FileSystemException(msg, path);
throw expectedType == FileSystemEntityType.FILE
? common.isADirectory(path)
: common.notADirectory(path);
}
fileSystem.delegate.link(real(path)).deleteSync();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/backends/memory/memory_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
);
if (node.type != expectedType) {
// There was an existing non-directory node at this object's path
throw new io.FileSystemException('File exists', path);
throw common.notADirectory(path);
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
newPath,
validateOverwriteExistingEntity: (_DirectoryNode existingNode) {
if (existingNode.children.isNotEmpty) {
throw new io.FileSystemException('Directory not empty', newPath);
throw common.directoryNotEmpty(newPath);
}
},
);
Expand Down
11 changes: 5 additions & 6 deletions lib/src/backends/memory/memory_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _MemoryFile extends _MemoryFileSystemEntity implements File {
if (node.type != expectedType) {
// There was an existing non-file entity at this object's path
assert(node.type == FileSystemEntityType.DIRECTORY);
throw new io.FileSystemException('Is a directory', path);
throw common.isADirectory(path);
}
return node;
}
Expand All @@ -66,10 +66,9 @@ class _MemoryFile extends _MemoryFileSystemEntity implements File {
checkType: (_Node node) {
FileSystemEntityType actualType = node.stat.type;
if (actualType != expectedType) {
String msg = actualType == FileSystemEntityType.NOT_FOUND
? 'No such file or directory'
: 'Is a directory';
throw new FileSystemException(msg, path);
throw actualType == FileSystemEntityType.NOT_FOUND
? common.noSuchFileOrDirectory(path)
: common.isADirectory(path);
}
},
);
Expand Down Expand Up @@ -231,7 +230,7 @@ class _MemoryFile extends _MemoryFileSystemEntity implements File {
bool flush: false,
}) {
if (!_isWriteMode(mode)) {
throw new FileSystemException('Bad file descriptor', path);
throw common.badFileDescriptor(path);
}
_FileNode node = _resolvedBackingOrCreate;
_truncateIfNecessary(node, mode);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/backends/memory/memory_file_system_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ abstract class _MemoryFileSystemEntity implements FileSystemEntity {
_Node node = _backing;
if (!recursive) {
if (node is _DirectoryNode && node.children.isNotEmpty) {
throw new io.FileSystemException('Directory not empty', path);
throw common.directoryNotEmpty(path);
}
(checkType ?? _defaultCheckType)(node);
}
Expand Down
11 changes: 5 additions & 6 deletions lib/src/backends/memory/memory_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ class _MemoryLink extends _MemoryFileSystemEntity implements Link {
newPath,
checkType: (_Node node) {
if (node.type != expectedType) {
throw new FileSystemException(
node.type == FileSystemEntityType.DIRECTORY
? 'Is a directory'
: 'Invalid argument');
throw node.type == FileSystemEntityType.DIRECTORY
? common.isADirectory(newPath)
: common.invalidArgument(newPath);
}
},
);
Expand All @@ -50,7 +49,7 @@ class _MemoryLink extends _MemoryFileSystemEntity implements Link {
});
if (preexisting) {
// Per the spec, this is an error.
throw new io.FileSystemException('File exists', path);
throw common.fileExists(path);
}
}

Expand Down Expand Up @@ -82,7 +81,7 @@ class _MemoryLink extends _MemoryFileSystemEntity implements Link {
_Node node = _backing;
if (node.type != expectedType) {
// Note: this may change; https://github.com/dart-lang/sdk/issues/28204
throw new FileSystemException('No such file or directory', path);
throw common.noSuchFileOrDirectory(path);
}
return (node as _LinkNode).target;
}
Expand Down
18 changes: 6 additions & 12 deletions lib/src/backends/memory/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ typedef void _TypeChecker(_Node node);
/// Throws a [io.FileSystemException] if [node] is null.
void _checkExists(_Node node, _PathGenerator path) {
if (node == null) {
throw new io.FileSystemException('No such file or directory', path());
throw common.noSuchFileOrDirectory(path());
}
}

/// Throws a [io.FileSystemException] if [node] is not a directory.
void _checkIsDir(_Node node, _PathGenerator path) {
if (!_isDirectory(node)) {
throw new io.FileSystemException('Not a directory', path());
throw common.notADirectory(path());
}
}

Expand All @@ -46,23 +46,18 @@ void _checkType(
_PathGenerator path,
) {
if (expectedType != actualType) {
String msg;
switch (expectedType) {
case FileSystemEntityType.DIRECTORY:
msg = 'Not a directory';
break;
throw common.notADirectory(path());
case FileSystemEntityType.FILE:
assert(actualType == FileSystemEntityType.DIRECTORY);
msg = 'Is a directory';
break;
throw common.isADirectory(path());
case FileSystemEntityType.LINK:
msg = 'Invalid argument';
break;
throw common.invalidArgument(path());
default:
// Should not happen
throw new AssertionError();
}
throw new io.FileSystemException(msg, path());
}
}

Expand Down Expand Up @@ -111,8 +106,7 @@ _Node _resolveLinks(
while (_isLink(node)) {
link = node;
if (!breadcrumbs.add(node)) {
throw new io.FileSystemException(
'Too many levels of symbolic links', path());
throw common.tooManyLevelsOfSymbolicLinks(path());
}
if (ledger != null) {
if (_isAbsolute(link.target)) {
Expand Down
Loading