From aa3c39a78e1ef0f01b91de1d4b420da0ef8dfeef Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Tue, 21 Feb 2017 18:51:22 -0800 Subject: [PATCH 1/5] Windows support.... --- lib/src/interface.dart | 1 + lib/src/interface/error_code.dart | 780 +++++++++++++++++++++++++++++ lib/src/testing/core_matchers.dart | 54 +- test/common_tests.dart | 275 +++++----- 4 files changed, 942 insertions(+), 168 deletions(-) create mode 100644 lib/src/interface/error_code.dart diff --git a/lib/src/interface.dart b/lib/src/interface.dart index db86876..4f2ec7c 100644 --- a/lib/src/interface.dart +++ b/lib/src/interface.dart @@ -14,6 +14,7 @@ import 'io.dart' as io; export 'io.dart'; part 'interface/directory.dart'; +part 'interface/error_code.dart'; part 'interface/file.dart'; part 'interface/file_system.dart'; part 'interface/file_system_entity.dart'; diff --git a/lib/src/interface/error_code.dart b/lib/src/interface/error_code.dart new file mode 100644 index 0000000..0657b49 --- /dev/null +++ b/lib/src/interface/error_code.dart @@ -0,0 +1,780 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +part of file.src.interface; + +/// Operating system error codes. +abstract class ErrorCodes { + ErrorCodes._(); + + /// TODO + static ErrorCodes get linux => const _LinuxErrorCodes(); + + /// TODO + static ErrorCodes get macos => const _MacosErrorCodes(); + + /// Operation not permitted + int get EPERM; // ignore: non_constant_identifier_names + + /// No such file or directory + int get ENOENT; // ignore: non_constant_identifier_names + + /// No such process + int get ESRCH; // ignore: non_constant_identifier_names + + /// Interrupted system call + int get EINTR; // ignore: non_constant_identifier_names + + /// I/O error + int get EIO; // ignore: non_constant_identifier_names + + /// No such device or address + int get ENXIO; // ignore: non_constant_identifier_names + + /// Argument list too long + int get E2BIG; // ignore: non_constant_identifier_names + + /// Exec format error + int get ENOEXEC; // ignore: non_constant_identifier_names + + /// Bad file number + int get EBADF; // ignore: non_constant_identifier_names + + /// No child processes + int get ECHILD; // ignore: non_constant_identifier_names + + /// Try again + int get EAGAIN; // ignore: non_constant_identifier_names + + /// Out of memory + int get ENOMEM; // ignore: non_constant_identifier_names + + /// Permission denied + int get EACCES; // ignore: non_constant_identifier_names + + /// Bad address + int get EFAULT; // ignore: non_constant_identifier_names + + /// Block device required + int get ENOTBLK; // ignore: non_constant_identifier_names + + /// Device or resource busy + int get EBUSY; // ignore: non_constant_identifier_names + + /// File exists + int get EEXIST; // ignore: non_constant_identifier_names + + /// Cross-device link + int get EXDEV; // ignore: non_constant_identifier_names + + /// No such device + int get ENODEV; // ignore: non_constant_identifier_names + + /// Not a directory + int get ENOTDIR; // ignore: non_constant_identifier_names + + /// Is a directory + int get EISDIR; // ignore: non_constant_identifier_names + + /// Invalid argument + int get EINVAL; // ignore: non_constant_identifier_names + + /// File table overflow + int get ENFILE; // ignore: non_constant_identifier_names + + /// Too many open files + int get EMFILE; // ignore: non_constant_identifier_names + + /// Not a typewriter + int get ENOTTY; // ignore: non_constant_identifier_names + + /// Text file busy + int get ETXTBSY; // ignore: non_constant_identifier_names + + /// File too large + int get EFBIG; // ignore: non_constant_identifier_names + + /// No space left on device + int get ENOSPC; // ignore: non_constant_identifier_names + + /// Illegal seek + int get ESPIPE; // ignore: non_constant_identifier_names + + /// Read-only file system + int get EROFS; // ignore: non_constant_identifier_names + + /// Too many links + int get EMLINK; // ignore: non_constant_identifier_names + + /// Broken pipe + int get EPIPE; // ignore: non_constant_identifier_names + + /// Math argument out of domain of func + int get EDOM; // ignore: non_constant_identifier_names + + /// Math result not representable + int get ERANGE; // ignore: non_constant_identifier_names + + /// File name too long + int get ENAMETOOLONG; // ignore: non_constant_identifier_names + + /// No record locks available + int get ENOLCK; // ignore: non_constant_identifier_names + + /// Function not implemented + int get ENOSYS; // ignore: non_constant_identifier_names + + /// Directory not empty + int get ENOTEMPTY; // ignore: non_constant_identifier_names + + /// Too many symbolic links encountered + int get ELOOP; // ignore: non_constant_identifier_names + + /// Operation would block + int get EWOULDBLOCK; // ignore: non_constant_identifier_names + + /// No message of desired type + int get ENOMSG; // ignore: non_constant_identifier_names + + /// Identifier removed + int get EIDRM; // ignore: non_constant_identifier_names + + /// Device not a stream + int get ENOSTR; // ignore: non_constant_identifier_names + + /// No data available + int get ENODATA; // ignore: non_constant_identifier_names + + /// Timer expired + int get ETIME; // ignore: non_constant_identifier_names + + /// Out of streams resources + int get ENOSR; // ignore: non_constant_identifier_names + + /// Object is remote + int get EREMOTE; // ignore: non_constant_identifier_names + + /// Link has been severed + int get ENOLINK; // ignore: non_constant_identifier_names + + /// Protocol error + int get EPROTO; // ignore: non_constant_identifier_names + + /// Multihop attempted + int get EMULTIHOP; // ignore: non_constant_identifier_names + + /// Not a data message + int get EBADMSG; // ignore: non_constant_identifier_names + + /// Value too large for defined data type + int get EOVERFLOW; // ignore: non_constant_identifier_names + + /// Illegal byte sequence + int get EILSEQ; // ignore: non_constant_identifier_names + + /// Too many users + int get EUSERS; // ignore: non_constant_identifier_names + + /// Socket operation on non-socket + int get ENOTSOCK; // ignore: non_constant_identifier_names + + /// Destination address required + int get EDESTADDRREQ; // ignore: non_constant_identifier_names + + /// Message too long + int get EMSGSIZE; // ignore: non_constant_identifier_names + + /// Protocol wrong type for socket + int get EPROTOTYPE; // ignore: non_constant_identifier_names + + /// Protocol not available + int get ENOPROTOOPT; // ignore: non_constant_identifier_names + + /// Protocol not supported + int get EPROTONOSUPPORT; // ignore: non_constant_identifier_names + + /// Socket type not supported + int get ESOCKTNOSUPPORT; // ignore: non_constant_identifier_names + + /// Protocol family not supported + int get EPFNOSUPPORT; // ignore: non_constant_identifier_names + + /// Address family not supported by protocol + int get EAFNOSUPPORT; // ignore: non_constant_identifier_names + + /// Address already in use + int get EADDRINUSE; // ignore: non_constant_identifier_names + + /// Cannot assign requested address + int get EADDRNOTAVAIL; // ignore: non_constant_identifier_names + + /// Network is down + int get ENETDOWN; // ignore: non_constant_identifier_names + + /// Network is unreachable + int get ENETUNREACH; // ignore: non_constant_identifier_names + + /// Network dropped connection because of reset + int get ENETRESET; // ignore: non_constant_identifier_names + + /// Software caused connection abort + int get ECONNABORTED; // ignore: non_constant_identifier_names + + /// Connection reset by peer + int get ECONNRESET; // ignore: non_constant_identifier_names + + /// No buffer space available + int get ENOBUFS; // ignore: non_constant_identifier_names + + /// Transport endpoint is already connected + int get EISCONN; // ignore: non_constant_identifier_names + + /// Transport endpoint is not connected + int get ENOTCONN; // ignore: non_constant_identifier_names + + /// Cannot send after transport endpoint shutdown + int get ESHUTDOWN; // ignore: non_constant_identifier_names + + /// Too many references: cannot splice + int get ETOOMANYREFS; // ignore: non_constant_identifier_names + + /// Connection timed out + int get ETIMEDOUT; // ignore: non_constant_identifier_names + + /// Connection refused + int get ECONNREFUSED; // ignore: non_constant_identifier_names + + /// Host is down + int get EHOSTDOWN; // ignore: non_constant_identifier_names + + /// No route to host + int get EHOSTUNREACH; // ignore: non_constant_identifier_names + + /// Operation already in progress + int get EALREADY; // ignore: non_constant_identifier_names + + /// Operation now in progress + int get EINPROGRESS; // ignore: non_constant_identifier_names + + /// Stale NFS file handle + int get ESTALE; // ignore: non_constant_identifier_names + + /// Quota exceeded + int get EDQUOT; // ignore: non_constant_identifier_names + + /// Operation Canceled + int get ECANCELED; // ignore: non_constant_identifier_names +} + +class _LinuxErrorCodes implements ErrorCodes { + const _LinuxErrorCodes(); + + @override + final int EPERM = 1; // ignore: non_constant_identifier_names + + @override + final int ENOENT = 2; // ignore: non_constant_identifier_names + + @override + final int ESRCH = 3; // ignore: non_constant_identifier_names + + @override + final int EINTR = 4; // ignore: non_constant_identifier_names + + @override + final int EIO = 5; // ignore: non_constant_identifier_names + + @override + final int ENXIO = 6; // ignore: non_constant_identifier_names + + @override + final int E2BIG = 7; // ignore: non_constant_identifier_names + + @override + final int ENOEXEC = 8; // ignore: non_constant_identifier_names + + @override + final int EBADF = 9; // ignore: non_constant_identifier_names + + @override + final int ECHILD = 10; // ignore: non_constant_identifier_names + + @override + final int EAGAIN = 11; // ignore: non_constant_identifier_names + + @override + final int ENOMEM = 12; // ignore: non_constant_identifier_names + + @override + final int EACCES = 13; // ignore: non_constant_identifier_names + + @override + final int EFAULT = 14; // ignore: non_constant_identifier_names + + @override + final int ENOTBLK = 15; // ignore: non_constant_identifier_names + + @override + final int EBUSY = 16; // ignore: non_constant_identifier_names + + @override + final int EEXIST = 17; // ignore: non_constant_identifier_names + + @override + final int EXDEV = 18; // ignore: non_constant_identifier_names + + @override + final int ENODEV = 19; // ignore: non_constant_identifier_names + + @override + final int ENOTDIR = 20; // ignore: non_constant_identifier_names + + @override + final int EISDIR = 21; // ignore: non_constant_identifier_names + + @override + final int EINVAL = 22; // ignore: non_constant_identifier_names + + @override + final int ENFILE = 23; // ignore: non_constant_identifier_names + + @override + final int EMFILE = 24; // ignore: non_constant_identifier_names + + @override + final int ENOTTY = 25; // ignore: non_constant_identifier_names + + @override + final int ETXTBSY = 26; // ignore: non_constant_identifier_names + + @override + final int EFBIG = 27; // ignore: non_constant_identifier_names + + @override + final int ENOSPC = 28; // ignore: non_constant_identifier_names + + @override + final int ESPIPE = 29; // ignore: non_constant_identifier_names + + @override + final int EROFS = 30; // ignore: non_constant_identifier_names + + @override + final int EMLINK = 31; // ignore: non_constant_identifier_names + + @override + final int EPIPE = 32; // ignore: non_constant_identifier_names + + @override + final int EDOM = 33; // ignore: non_constant_identifier_names + + @override + final int ERANGE = 34; // ignore: non_constant_identifier_names + + @override + final int ENAMETOOLONG = 36; // ignore: non_constant_identifier_names + + @override + final int ENOLCK = 37; // ignore: non_constant_identifier_names + + @override + final int ENOSYS = 38; // ignore: non_constant_identifier_names + + @override + final int ENOTEMPTY = 39; // ignore: non_constant_identifier_names + + @override + final int ELOOP = 40; // ignore: non_constant_identifier_names + + @override + final int EWOULDBLOCK = 11/*EAGAIN*/; // ignore: non_constant_identifier_names + + @override + final int ENOMSG = 42; // ignore: non_constant_identifier_names + + @override + final int EIDRM = 43; // ignore: non_constant_identifier_names + + @override + final int ENOSTR = 60; // ignore: non_constant_identifier_names + + @override + final int ENODATA = 61; // ignore: non_constant_identifier_names + + @override + final int ETIME = 62; // ignore: non_constant_identifier_names + + @override + final int ENOSR = 63; // ignore: non_constant_identifier_names + + @override + final int EREMOTE = 66; // ignore: non_constant_identifier_names + + @override + final int ENOLINK = 67; // ignore: non_constant_identifier_names + + @override + final int EPROTO = 71; // ignore: non_constant_identifier_names + + @override + final int EMULTIHOP = 72; // ignore: non_constant_identifier_names + + @override + final int EBADMSG = 74; // ignore: non_constant_identifier_names + + @override + final int EOVERFLOW = 75; // ignore: non_constant_identifier_names + + @override + final int EILSEQ = 84; // ignore: non_constant_identifier_names + + @override + final int EUSERS = 87; // ignore: non_constant_identifier_names + + @override + final int ENOTSOCK = 88; // ignore: non_constant_identifier_names + + @override + final int EDESTADDRREQ = 89; // ignore: non_constant_identifier_names + + @override + final int EMSGSIZE = 90; // ignore: non_constant_identifier_names + + @override + final int EPROTOTYPE = 91; // ignore: non_constant_identifier_names + + @override + final int ENOPROTOOPT = 92; // ignore: non_constant_identifier_names + + @override + final int EPROTONOSUPPORT = 93; // ignore: non_constant_identifier_names + + @override + final int ESOCKTNOSUPPORT = 94; // ignore: non_constant_identifier_names + + @override + final int EPFNOSUPPORT = 96; // ignore: non_constant_identifier_names + + @override + final int EAFNOSUPPORT = 97; // ignore: non_constant_identifier_names + + @override + final int EADDRINUSE = 98; // ignore: non_constant_identifier_names + + @override + final int EADDRNOTAVAIL = 99; // ignore: non_constant_identifier_names + + @override + final int ENETDOWN = 100; // ignore: non_constant_identifier_names + + @override + final int ENETUNREACH = 101; // ignore: non_constant_identifier_names + + @override + final int ENETRESET = 102; // ignore: non_constant_identifier_names + + @override + final int ECONNABORTED = 103; // ignore: non_constant_identifier_names + + @override + final int ECONNRESET = 104; // ignore: non_constant_identifier_names + + @override + final int ENOBUFS = 105; // ignore: non_constant_identifier_names + + @override + final int EISCONN = 106; // ignore: non_constant_identifier_names + + @override + final int ENOTCONN = 107; // ignore: non_constant_identifier_names + + @override + final int ESHUTDOWN = 108; // ignore: non_constant_identifier_names + + @override + final int ETOOMANYREFS = 109; // ignore: non_constant_identifier_names + + @override + final int ETIMEDOUT = 110; // ignore: non_constant_identifier_names + + @override + final int ECONNREFUSED = 111; // ignore: non_constant_identifier_names + + @override + final int EHOSTDOWN = 112; // ignore: non_constant_identifier_names + + @override + final int EHOSTUNREACH = 113; // ignore: non_constant_identifier_names + + @override + final int EALREADY = 114; // ignore: non_constant_identifier_names + + @override + final int EINPROGRESS = 115; // ignore: non_constant_identifier_names + + @override + final int ESTALE = 116; // ignore: non_constant_identifier_names + + @override + final int EDQUOT = 122; // ignore: non_constant_identifier_names + + @override + final int ECANCELED = 125; // ignore: non_constant_identifier_names +} + +class _MacosErrorCodes implements ErrorCodes { + const _MacosErrorCodes(); + + @override + final int EPERM = 1; // ignore: non_constant_identifier_names + + @override + final int ENOENT = 2; // ignore: non_constant_identifier_names + + @override + final int ESRCH = 3; // ignore: non_constant_identifier_names + + @override + final int EINTR = 4; // ignore: non_constant_identifier_names + + @override + final int EIO = 5; // ignore: non_constant_identifier_names + + @override + final int ENXIO = 6; // ignore: non_constant_identifier_names + + @override + final int E2BIG = 7; // ignore: non_constant_identifier_names + + @override + final int ENOEXEC = 8; // ignore: non_constant_identifier_names + + @override + final int EBADF = 9; // ignore: non_constant_identifier_names + + @override + final int ECHILD = 10; // ignore: non_constant_identifier_names + + @override + final int ENOMEM = 12; // ignore: non_constant_identifier_names + + @override + final int EACCES = 13; // ignore: non_constant_identifier_names + + @override + final int EFAULT = 14; // ignore: non_constant_identifier_names + + @override + final int ENOTBLK = 15; // ignore: non_constant_identifier_names + + @override + final int EBUSY = 16; // ignore: non_constant_identifier_names + + @override + final int EEXIST = 17; // ignore: non_constant_identifier_names + + @override + final int EXDEV = 18; // ignore: non_constant_identifier_names + + @override + final int ENODEV = 19; // ignore: non_constant_identifier_names + + @override + final int ENOTDIR = 20; // ignore: non_constant_identifier_names + + @override + final int EISDIR = 21; // ignore: non_constant_identifier_names + + @override + final int EINVAL = 22; // ignore: non_constant_identifier_names + + @override + final int ENFILE = 23; // ignore: non_constant_identifier_names + + @override + final int EMFILE = 24; // ignore: non_constant_identifier_names + + @override + final int ENOTTY = 25; // ignore: non_constant_identifier_names + + @override + final int ETXTBSY = 26; // ignore: non_constant_identifier_names + + @override + final int EFBIG = 27; // ignore: non_constant_identifier_names + + @override + final int ENOSPC = 28; // ignore: non_constant_identifier_names + + @override + final int ESPIPE = 29; // ignore: non_constant_identifier_names + + @override + final int EROFS = 30; // ignore: non_constant_identifier_names + + @override + final int EMLINK = 31; // ignore: non_constant_identifier_names + + @override + final int EPIPE = 32; // ignore: non_constant_identifier_names + + @override + final int EDOM = 33; // ignore: non_constant_identifier_names + + @override + final int ERANGE = 34; // ignore: non_constant_identifier_names + + @override + final int EAGAIN = 35; // ignore: non_constant_identifier_names + + @override + final int EWOULDBLOCK = 35 /*EAGAIN*/; // ignore: non_constant_identifier_names + + @override + final int EINPROGRESS = 36; // ignore: non_constant_identifier_names + + @override + final int EALREADY = 37; // ignore: non_constant_identifier_names + + @override + final int ENOTSOCK = 38; // ignore: non_constant_identifier_names + + @override + final int EDESTADDRREQ = 39; // ignore: non_constant_identifier_names + + @override + final int EMSGSIZE = 40; // ignore: non_constant_identifier_names + + @override + final int EPROTOTYPE = 41; // ignore: non_constant_identifier_names + + @override + final int ENOPROTOOPT = 42; // ignore: non_constant_identifier_names + + @override + final int EPROTONOSUPPORT = 43; // ignore: non_constant_identifier_names + + @override + final int ESOCKTNOSUPPORT = 44; // ignore: non_constant_identifier_names + + @override + final int EPFNOSUPPORT = 46; // ignore: non_constant_identifier_names + + @override + final int EAFNOSUPPORT = 47; // ignore: non_constant_identifier_names + + @override + final int EADDRINUSE = 48; // ignore: non_constant_identifier_names + + @override + final int EADDRNOTAVAIL = 49; // ignore: non_constant_identifier_names + + @override + final int ENETDOWN = 50; // ignore: non_constant_identifier_names + + @override + final int ENETUNREACH = 51; // ignore: non_constant_identifier_names + + @override + final int ENETRESET = 52; // ignore: non_constant_identifier_names + + @override + final int ECONNABORTED = 53; // ignore: non_constant_identifier_names + + @override + final int ECONNRESET = 54; // ignore: non_constant_identifier_names + + @override + final int ENOBUFS = 55; // ignore: non_constant_identifier_names + + @override + final int EISCONN = 56; // ignore: non_constant_identifier_names + + @override + final int ENOTCONN = 57; // ignore: non_constant_identifier_names + + @override + final int ESHUTDOWN = 58; // ignore: non_constant_identifier_names + + @override + final int ETOOMANYREFS = 59; // ignore: non_constant_identifier_names + + @override + final int ETIMEDOUT = 60; // ignore: non_constant_identifier_names + + @override + final int ECONNREFUSED = 61; // ignore: non_constant_identifier_names + + @override + final int ELOOP = 62; // ignore: non_constant_identifier_names + + @override + final int ENAMETOOLONG = 63; // ignore: non_constant_identifier_names + + @override + final int EHOSTDOWN = 64; // ignore: non_constant_identifier_names + + @override + final int EHOSTUNREACH = 65; // ignore: non_constant_identifier_names + + @override + final int ENOTEMPTY = 66; // ignore: non_constant_identifier_names + + @override + final int EUSERS = 68; // ignore: non_constant_identifier_names + + @override + final int EDQUOT = 69; // ignore: non_constant_identifier_names + + @override + final int ESTALE = 70; // ignore: non_constant_identifier_names + + @override + final int EREMOTE = 71; // ignore: non_constant_identifier_names + + @override + final int ENOLCK = 77; // ignore: non_constant_identifier_names + + @override + final int ENOSYS = 78; // ignore: non_constant_identifier_names + + @override + final int EOVERFLOW = 84; // ignore: non_constant_identifier_names + + @override + final int ECANCELED = 89; // ignore: non_constant_identifier_names + + @override + final int EIDRM = 90; // ignore: non_constant_identifier_names + + @override + final int ENOMSG = 91; // ignore: non_constant_identifier_names + + @override + final int EILSEQ = 92; // ignore: non_constant_identifier_names + + @override + final int EBADMSG = 94; // ignore: non_constant_identifier_names + + @override + final int EMULTIHOP = 95; // ignore: non_constant_identifier_names + + @override + final int ENODATA = 96; // ignore: non_constant_identifier_names + + @override + final int ENOLINK = 97; // ignore: non_constant_identifier_names + + @override + final int ENOSR = 98; // ignore: non_constant_identifier_names + + @override + final int ENOSTR = 99; // ignore: non_constant_identifier_names + + @override + final int EPROTO = 100; // ignore: non_constant_identifier_names + + @override + final int ETIME = 101; // ignore: non_constant_identifier_names +} diff --git a/lib/src/testing/core_matchers.dart b/lib/src/testing/core_matchers.dart index b6868e9..eabbaab 100644 --- a/lib/src/testing/core_matchers.dart +++ b/lib/src/testing/core_matchers.dart @@ -30,31 +30,36 @@ Matcher hasPath(dynamic path) => new _HasPath(path); /// Returns a [Matcher] that successfully matches against an instance of /// [FileSystemException]. /// -/// If [message] is specified, matches will be limited to exceptions with a -/// matching `message` (either in the exception itself or in the nested -/// [OSError]). +/// If [osErrorCode] is specified, matches will be limited to exceptions whose +/// `osError.errorCode` also match the specified matcher. /// -/// [message] may be a String, a predicate function, or a [Matcher]. If it is -/// a String, it will be wrapped in an equality matcher. -Matcher isFileSystemException([dynamic message]) => - new _FileSystemException(message); +/// [osErrorCode] may be an `int`, a predicate function, or a [Matcher]. If it +/// is an `int`, it will be wrapped in an equality matcher. +Matcher isFileSystemException([dynamic osErrorCode]) => + new _FileSystemException(osErrorCode); /// Returns a matcher that successfully matches against a future or function /// that throws a [FileSystemException]. /// -/// If [message] is specified, matches will be limited to exceptions with a -/// matching `message` (either in the exception itself or in the nested -/// [OSError]). +/// If [osErrorCode] is specified, matches will be limited to exceptions whose +/// `osError.errorCode` also match the specified matcher. /// -/// [message] may be a String, a predicate function, or a [Matcher]. If it is -/// a String, it will be wrapped in an equality matcher. -Matcher throwsFileSystemException([dynamic message]) => - throwsA(isFileSystemException(message)); +/// [osErrorCode] may be an `int`, a predicate function, or a [Matcher]. If it +/// is an `int`, it will be wrapped in an equality matcher. +Matcher throwsFileSystemException([dynamic osErrorCode]) => + throwsA(isFileSystemException(osErrorCode)); /// Expects the specified [callback] to throw a [FileSystemException] with the -/// specified [message]. -void expectFileSystemException(dynamic message, void callback()) { - expect(callback, throwsFileSystemException(message)); +/// specified [osErrorCode] (matched against the exception's +/// `osError.errorCode`). +/// +/// [osErrorCode] may be an `int`, a predicate function, or a [Matcher]. If it +/// is an `int`, it will be wrapped in an equality matcher. +/// +/// See also: +/// - [ErrorCode] +void expectFileSystemException(dynamic osErrorCode, void callback()) { + expect(callback, throwsFileSystemException(osErrorCode)); } /// Matcher that successfully matches against a [FileSystemEntity] that @@ -64,23 +69,26 @@ const Matcher exists = const _Exists(); class _FileSystemException extends Matcher { final Matcher _matcher; - _FileSystemException(dynamic message) - : _matcher = message == null ? null : wrapMatcher(message); + _FileSystemException(dynamic osErrorCode) + : _matcher = osErrorCode == null ? null : wrapMatcher(osErrorCode); @override bool matches(dynamic item, Map matchState) { if (item is FileSystemException) { return (_matcher == null || - _matcher.matches(item.message, matchState) || - _matcher.matches(item.osError?.message, matchState)); + _matcher.matches(item.osError?.errorCode, matchState)); } return false; } @override Description describe(Description desc) { - desc.add('FileSystemException with message: '); - return _matcher.describe(desc); + if (_matcher == null) { + return desc.add('FileSystemException'); + } else { + desc.add('FileSystemException with osError.errorCode: '); + return _matcher.describe(desc); + } } } diff --git a/test/common_tests.dart b/test/common_tests.dart index 206b9c5..1b2e19f 100644 --- a/test/common_tests.dart +++ b/test/common_tests.dart @@ -227,14 +227,14 @@ void runCommonTests( }); test('throwsIfSetToNonExistentPath', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.currentDirectory = ns('/foo'); }); }); test('throwsIfHasNonExistentPathInComplexChain', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.currentDirectory = ns('/bar/../foo'); }); }); @@ -295,14 +295,14 @@ void runCommonTests( test('throwsIfSetToFilePathSegmentAtTail', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.currentDirectory = ns('/foo'); }); }); test('throwsIfSetToFilePathSegmentViaTraversal', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.currentDirectory = ns('/foo/bar/baz'); }); }); @@ -325,7 +325,7 @@ void runCommonTests( test('throwsIfSetToLinkLoop', () { fs.link(ns('/foo')).createSync(ns('/bar')); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Too many levels of symbolic links', () { + expectFileSystemException(ErrorCodes.linux.ETIME, () { fs.currentDirectory = ns('/foo'); }); }); @@ -395,14 +395,14 @@ void runCommonTests( }); test('throwsForDifferentPathsToNonExistentEntities', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.identicalSync(ns('/foo'), ns('/bar')); }); }); test('throwsForDifferentPathsToOneFileOneNonExistentEntity', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.identicalSync(ns('/foo'), ns('/bar')); }); }); @@ -519,10 +519,7 @@ void runCommonTests( test('throwsIfAlreadyExistsAsFile', () { fs.file(ns('/foo')).createSync(); - // TODO(tvolkert): Change this to just be 'Not a directory' - // once Dart 1.22 is stable. - String pattern = '(File exists|Not a directory)'; - expectFileSystemException(matches(pattern), () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.directory(ns('/foo')).createSync(); }); }); @@ -536,24 +533,21 @@ void runCommonTests( test('throwsIfAlreadyExistsAsLinkToFile', () { fs.file(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - // TODO(tvolkert): Change this to just be 'Not a directory' - // once Dart 1.22 is stable. - String pattern = '(File exists|Not a directory)'; - expectFileSystemException(matches(pattern), () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.directory(ns('/bar')).createSync(); }); }); test('throwsIfAlreadyExistsAsLinkToNotFoundAtTail', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).createSync(); }); }); test('throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal', () { fs.link(ns('/foo')).createSync(ns('/bar/baz')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).createSync(); }); }); @@ -562,7 +556,7 @@ void runCommonTests( fs.directory(ns('/foo')).createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/bar/baz')).createSync(ns('/foo/qux')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/bar/baz')).createSync(); }); }); @@ -574,7 +568,7 @@ void runCommonTests( }); test('throwsIfAncestorDoesntExistRecursiveFalse', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo/bar')).createSync(); }); }); @@ -611,14 +605,14 @@ void runCommonTests( test('throwsIfDestinationIsFile', () { fs.file(ns('/bar')).createSync(); Directory src = fs.directory(ns('/foo'))..createSync(); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { src.renameSync(ns('/bar')); }); }); test('throwsIfDestinationParentFolderDoesntExist', () { Directory src = fs.directory(ns('/foo'))..createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { src.renameSync(ns('/bar/baz')); }); }); @@ -626,26 +620,21 @@ void runCommonTests( test('throwsIfDestinationIsNonEmptyDirectory', () { fs.file(ns('/bar/baz')).createSync(recursive: true); Directory src = fs.directory(ns('/foo'))..createSync(); - // The error will be 'Directory not empty' on OS X, but it will be - // 'File exists' on Linux, so we just ignore it here in the test. - expectFileSystemException(null, () { - src.renameSync(ns('/bar')); - }); + expectFileSystemException( + anyOf(ErrorCodes.macos.ENOTEMPTY, ErrorCodes.linux.EEXIST), + () => src.renameSync(ns('/bar')), + ); }); test('throwsIfSourceDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceIsFile', () { fs.file(ns('/foo')).createSync(); - // The error message is usually 'No such file or directory', but - // it's occasionally 'Not a directory', 'Directory not empty', - // 'File exists', or 'Undefined error'. - // https://github.com/dart-lang/sdk/issues/28147 - expectFileSystemException(null, () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.directory(ns('/foo')).renameSync(ns('/bar')); }); }); @@ -665,7 +654,7 @@ void runCommonTests( test('throwsIfDestinationIsLinkToNotFound', () { Directory src = fs.directory(ns('/foo'))..createSync(); fs.link(ns('/bar')).createSync(ns('/baz')); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { src.renameSync(ns('/bar')); }); }); @@ -674,7 +663,7 @@ void runCommonTests( Directory src = fs.directory(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/baz')).createSync(ns('/bar')); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { src.renameSync(ns('/baz')); }); }); @@ -723,9 +712,10 @@ void runCommonTests( test('throwsIfNonEmptyDirectoryExistsAndRecursiveFalse', () { Directory dir = fs.directory(ns('/foo'))..createSync(); fs.file(ns('/foo/bar')).createSync(); - expectFileSystemException('Directory not empty', () { - dir.deleteSync(); - }); + expectFileSystemException( + anyOf(ErrorCodes.linux.ENOTEMPTY, ErrorCodes.macos.ENOTEMPTY), + () => dir.deleteSync(), + ); }); test('succeedsIfNonEmptyDirectoryExistsAndRecursiveTrue', () { @@ -737,13 +727,13 @@ void runCommonTests( }); test('throwsIfDirectoryDoesntExistAndRecursiveFalse', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).deleteSync(); }); }); test('throwsIfDirectoryDoesntExistAndRecursiveTrue', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).deleteSync(recursive: true); }); }); @@ -756,7 +746,7 @@ void runCommonTests( test('throwsIfPathReferencesFileAndRecursiveFalse', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.directory(ns('/foo')).deleteSync(); }); }); @@ -804,14 +794,14 @@ void runCommonTests( test('throwsIfPathReferencesLinkToFileAndRecursiveFalse', () { fs.file(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.directory(ns('/bar')).deleteSync(); }); }); test('throwsIfPathReferencesLinkToNotFoundAndRecursiveFalse', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException('Not a directory', () { + expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { fs.directory(ns('/foo')).deleteSync(); }); }); @@ -826,26 +816,26 @@ void runCommonTests( fs.link(ns('/foo')).createSync(ns('/bar')); fs.link(ns('/bar')).createSync(ns('/baz')); fs.link(ns('/baz'))..createSync(ns('/foo')); - expectFileSystemException('Too many levels of symbolic links', () { + expectFileSystemException(ErrorCodes.linux.ETIME, () { fs.directory(ns('/foo')).resolveSymbolicLinksSync(); }); }); test('throwsIfPathNotFoundInTraversal', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo/bar')).resolveSymbolicLinksSync(); }); }); test('throwsIfPathNotFoundAtTail', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).resolveSymbolicLinksSync(); }); }); test('throwsIfPathNotFoundInMiddleThenBackedOut', () { fs.directory(ns('/foo/bar')).createSync(recursive: true); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo/baz/../bar')).resolveSymbolicLinksSync(); }); }); @@ -955,7 +945,7 @@ void runCommonTests( }); test('throwsIfDirectoryDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/foo')).createTempSync(); }); }); @@ -985,7 +975,7 @@ void runCommonTests( test('throwsWithNestedPathPrefixThatDoesntExist', () { Directory dir = fs.directory(ns('/foo'))..createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { dir.createTempSync('bar/baz'); }); }); @@ -1019,7 +1009,7 @@ void runCommonTests( }); test('throwsIfDirectoryDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.directory(ns('/bar')).listSync(); }); }); @@ -1122,7 +1112,7 @@ void runCommonTests( }); test('throwsIfAncestorDoesntExistRecursiveFalse', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo/bar')).createSync(); }); }); @@ -1134,7 +1124,7 @@ void runCommonTests( test('throwsIfAlreadyExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).createSync(); }); }); @@ -1142,7 +1132,7 @@ void runCommonTests( test('throwsIfAlreadyExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/bar')).createSync(); }); }); @@ -1165,10 +1155,10 @@ void runCommonTests( test('throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal', () { fs.link(ns('/foo')).createSync(ns('/bar/baz')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).createSync(); }); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).createSync(recursive: true); }); }); @@ -1176,7 +1166,7 @@ void runCommonTests( /* test('throwsIfPathSegmentIsLinkToNotFoundAndRecursiveTrue', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo/baz')).createSync(recursive: true); }); }); @@ -1210,7 +1200,7 @@ void runCommonTests( test('throwsIfDestinationDoesntExistViaTraversal', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { f.renameSync(ns('/bar/baz')); }); }); @@ -1226,7 +1216,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsDirectory', () { File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { f.renameSync(ns('/bar')); }); }); @@ -1247,7 +1237,7 @@ void runCommonTests( File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/baz')).createSync(ns('/bar')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { f.renameSync(ns('/baz')); }); }); @@ -1262,14 +1252,14 @@ void runCommonTests( }); test('throwsIfSourceDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).renameSync(ns('/bar')); }); }); @@ -1288,14 +1278,14 @@ void runCommonTests( test('throwsIfSourceExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/bar')).renameSync(ns('/baz')); }); }); test('throwsIfSourceExistsAsLinkToNotFound', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).renameSync(ns('/baz')); }); }); @@ -1320,7 +1310,7 @@ void runCommonTests( test('throwsIfDestinationDoesntExistViaTraversal', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { f.copySync(ns('/bar/baz')); }); }); @@ -1342,7 +1332,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsDirectory', () { File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { f.copySync(ns('/bar')); }); }); @@ -1370,20 +1360,20 @@ void runCommonTests( File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/baz')).createSync(ns('/bar')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { f.copySync(ns('/baz')); }); }); test('throwsIfSourceDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).copySync(ns('/bar')); }); }); test('throwsIfSourceExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).copySync(ns('/bar')); }); }); @@ -1454,14 +1444,14 @@ void runCommonTests( group('length', () { test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).lengthSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).lengthSync(); }); }); @@ -1505,14 +1495,14 @@ void runCommonTests( }); test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).lastAccessedSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).lastAccessedSync(); }); }); @@ -1532,14 +1522,14 @@ void runCommonTests( final DateTime time = new DateTime(1999); test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).setLastAccessedSync(time); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).setLastAccessedSync(time); }); }); @@ -1569,14 +1559,14 @@ void runCommonTests( }); test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).lastModifiedSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).lastModifiedSync(); }); }); @@ -1596,14 +1586,14 @@ void runCommonTests( final DateTime time = new DateTime(1999); test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).setLastModifiedSync(time); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).setLastModifiedSync(time); }); }); @@ -1626,7 +1616,7 @@ void runCommonTests( void testIfDoesntExistAtTail(FileMode mode) { if (mode == FileMode.READ) { test('throwsIfDoesntExistAtTail', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/bar')).openSync(mode: mode); }); }); @@ -1641,7 +1631,7 @@ void runCommonTests( void testThrowsIfDoesntExistViaTraversal(FileMode mode) { test('throwsIfDoesntExistViaTraversal', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/bar/baz')).openSync(mode: mode); }); }); @@ -1668,28 +1658,28 @@ void runCommonTests( test('succeedsIfClosedAfterClosed', () { raf.closeSync(); - expectFileSystemException('File closed', () { + expectFileSystemException(null, () { raf.closeSync(); }); }); test('throwsIfReadAfterClose', () { raf.closeSync(); - expectFileSystemException('File closed', () { + expectFileSystemException(null, () { raf.readByteSync(); }); }); test('throwsIfWriteAfterClose', () { raf.closeSync(); - expectFileSystemException('File closed', () { + expectFileSystemException(null, () { raf.writeByteSync(0xBAD); }); }); test('throwsIfTruncateAfterClose', () { raf.closeSync(); - expectFileSystemException('File closed', () { + expectFileSystemException(null, () { raf.truncateSync(0); }); }); @@ -1707,19 +1697,19 @@ void runCommonTests( if (mode == FileMode.WRITE_ONLY || mode == FileMode.WRITE_ONLY_APPEND) { test('throwsIfReadByte', () { - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { raf.readByteSync(); }); }); test('throwsIfRead', () { - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { raf.readSync(2); }); }); test('throwsIfReadInto', () { - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { raf.readIntoSync(new List(5)); }); }); @@ -1777,19 +1767,19 @@ void runCommonTests( if (mode == FileMode.READ) { test('throwsIfWriteByte', () { - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { raf.writeByteSync(0xBAD); }); }); test('throwsIfWriteFrom', () { - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { raf.writeFromSync([1, 2, 3, 4]); }); }); test('throwsIfWriteString', () { - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { raf.writeStringSync('This should throw.'); }); }); @@ -1927,7 +1917,7 @@ void runCommonTests( } test('throwsIfSetToNegativeNumber', () { - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { raf.setPositionSync(-12); }); }); @@ -1935,7 +1925,7 @@ void runCommonTests( if (mode == FileMode.READ) { test('throwsIfTruncate', () { - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { raf.truncateSync(5); }); }); @@ -1963,7 +1953,7 @@ void runCommonTests( }); test('throwsIfSetToNegativeNumber', () { - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { raf.truncateSync(-2); }); }); @@ -2000,7 +1990,7 @@ void runCommonTests( test('throwsIfDoesntExist', () { Stream> stream = fs.file(ns('/foo')).openRead(); expect(stream.drain(), - throwsFileSystemException('No such file or directory')); + throwsFileSystemException(ErrorCodes.linux.ENOENT)); }); test('succeedsIfExistsAsFile', () async { @@ -2015,7 +2005,8 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); Stream> stream = fs.file(ns('/foo')).openRead(); - expect(stream.drain(), throwsFileSystemException('Is a directory')); + expect(stream.drain(), + throwsFileSystemException(ErrorCodes.linux.EISDIR)); }); test('succeedsIfExistsAsLinkToFile', () async { @@ -2074,14 +2065,14 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); expect(fs.file(ns('/foo')).openWrite().close(), - throwsFileSystemException('Is a directory')); + throwsFileSystemException(ErrorCodes.linux.EISDIR)); }); test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); expect(fs.file(ns('/bar')).openWrite().close(), - throwsFileSystemException('Is a directory')); + throwsFileSystemException(ErrorCodes.linux.EISDIR)); }); test('throwsIfModeIsRead', () { @@ -2281,14 +2272,14 @@ void runCommonTests( group('readAsBytes', () { test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).readAsBytesSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).readAsBytesSync(); }); }); @@ -2296,7 +2287,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/bar')).readAsBytesSync(); }); }); @@ -2322,14 +2313,14 @@ void runCommonTests( group('readAsString', () { test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).readAsStringSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).readAsStringSync(); }); }); @@ -2337,7 +2328,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/bar')).readAsStringSync(); }); }); @@ -2370,14 +2361,14 @@ void runCommonTests( group('readAsLines', () { test('throwsIfDoesntExist', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).readAsLinesSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).readAsLinesSync(); }); }); @@ -2385,7 +2376,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/bar')).readAsLinesSync(); }); }); @@ -2431,7 +2422,7 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).writeAsBytesSync([1, 2, 3, 4]); }); }); @@ -2439,7 +2430,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).writeAsBytesSync([1, 2, 3, 4]); }); }); @@ -2453,7 +2444,7 @@ void runCommonTests( test('throwsIfFileModeRead', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { f.writeAsBytesSync([1], mode: FileMode.READ); }); }); @@ -2495,7 +2486,7 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).writeAsStringSync('Hello world'); }); }); @@ -2503,7 +2494,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).writeAsStringSync('Hello world'); }); }); @@ -2517,7 +2508,7 @@ void runCommonTests( test('throwsIfFileModeRead', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException('Bad file descriptor', () { + expectFileSystemException(ErrorCodes.linux.EBADF, () { f.writeAsStringSync('Hello world', mode: FileMode.READ); }); }); @@ -2633,13 +2624,13 @@ void runCommonTests( }); test('throwsIfDoesntExistAndRecursiveFalse', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).deleteSync(); }); }); test('throwsIfDoesntExistAndRecursiveTrue', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.file(ns('/foo')).deleteSync(recursive: true); }); }); @@ -2652,7 +2643,7 @@ void runCommonTests( test('throwsIfExistsAsDirectoryAndRecursiveFalse', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/foo')).deleteSync(); }); }); @@ -2685,7 +2676,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectoryAndRecursiveFalse', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.file(ns('/bar')).deleteSync(); }); }); @@ -2816,20 +2807,20 @@ void runCommonTests( }); test('throwsIfLinkDoesntExistAtTail', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo')).deleteSync(); }); }); test('throwsIfLinkDoesntExistViaTraversal', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo/bar')).deleteSync(); }); }); test('throwsIfPathReferencesFileAndRecursiveFalse', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { fs.link(ns('/foo')).deleteSync(); }); }); @@ -2843,10 +2834,7 @@ void runCommonTests( test('throwsIfPathReferencesDirectoryAndRecursiveFalse', () { fs.directory(ns('/foo')).createSync(); - // TODO(tvolkert): Change this to just be 'Is a directory' - // once Dart 1.22 is stable. - String pattern = '(Invalid argument|Is a directory)'; - expectFileSystemException(matches(pattern), () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.link(ns('/foo')).deleteSync(); }); }); @@ -2938,7 +2926,7 @@ void runCommonTests( }); test('throwsIfLinkDoesntExistViaTraversalAndRecursiveFalse', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo/bar')).createSync('baz'); }); }); @@ -2954,28 +2942,28 @@ void runCommonTests( test('throwsIfAlreadyExistsAsFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('File exists', () { + expectFileSystemException(ErrorCodes.linux.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/bar')); }); }); test('throwsIfAlreadyExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('File exists', () { + expectFileSystemException(ErrorCodes.linux.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/bar')); }); }); test('throwsIfAlreadyExistsWithSameTarget', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException('File exists', () { + expectFileSystemException(ErrorCodes.linux.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/bar')); }); }); test('throwsIfAlreadyExistsWithDifferentTarget', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException('File exists', () { + expectFileSystemException(ErrorCodes.linux.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/baz')); }); }); @@ -2988,30 +2976,27 @@ void runCommonTests( }); test('throwsIfLinkDoesntExistAtTail', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo')).updateSync(ns('/bar')); }); }); test('throwsIfLinkDoesntExistViaTraversal', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo/bar')).updateSync(ns('/baz')); }); }); test('throwsIfPathReferencesFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { fs.link(ns('/foo')).updateSync(ns('/bar')); }); }); test('throwsIfPathReferencesDirectory', () { fs.directory(ns('/foo')).createSync(); - // TODO(tvolkert): Change this to just be 'Is a directory' - // once Dart 1.22 is stable. - String pattern = '(Invalid argument|Is a directory)'; - expectFileSystemException(matches(pattern), () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.link(ns('/foo')).updateSync(ns('/bar')); }); }); @@ -3049,27 +3034,27 @@ void runCommonTests( group('target', () { test('throwsIfLinkDoesntExistAtTail', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo')).targetSync(); }); }); test('throwsIfLinkDoesntExistViaTraversal', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo/bar')).targetSync(); }); }); test('throwsIfPathReferencesFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo')).targetSync(); }); }); test('throwsIfPathReferencesDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo')).targetSync(); }); }); @@ -3106,27 +3091,27 @@ void runCommonTests( }); test('throwsIfSourceDoesntExistAtTail', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceDoesntExistViaTraversal', () { - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { fs.link(ns('/foo/bar')).renameSync(ns('/bar')); }); }); test('throwsIfSourceIsFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { fs.link(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceIsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException('Is a directory', () { + expectFileSystemException(ErrorCodes.linux.EISDIR, () { fs.link(ns('/foo')).renameSync(ns('/bar')); }); }); @@ -3189,7 +3174,7 @@ void runCommonTests( test('throwsIfDestinationDoesntExistViaTraversal', () { Link l = fs.link(ns('/foo'))..createSync(ns('/bar')); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.linux.ENOENT, () { l.renameSync(ns('/baz/qux')); }); }); @@ -3197,7 +3182,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsFile', () { Link l = fs.link(ns('/foo'))..createSync(ns('/bar')); fs.file(ns('/baz')).createSync(); - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { l.renameSync(ns('/baz')); }); }); @@ -3205,7 +3190,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsDirectory', () { Link l = fs.link(ns('/foo'))..createSync(ns('/bar')); fs.directory(ns('/baz')).createSync(); - expectFileSystemException('Invalid argument', () { + expectFileSystemException(ErrorCodes.linux.EINVAL, () { l.renameSync(ns('/baz')); }); }); From b85b41eb7415d76443ffa2bf7609570392386259 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Wed, 22 Feb 2017 10:52:45 -0800 Subject: [PATCH 2/5] Finish migration to ErrorCodes --- lib/src/backends/chroot/chroot_directory.dart | 40 +- lib/src/backends/chroot/chroot_file.dart | 32 +- .../backends/chroot/chroot_file_system.dart | 19 +- .../chroot/chroot_file_system_entity.dart | 28 +- lib/src/backends/memory/memory_directory.dart | 8 +- lib/src/backends/memory/memory_file.dart | 23 +- .../memory/memory_file_system_entity.dart | 4 +- lib/src/backends/memory/memory_link.dart | 21 +- lib/src/backends/memory/utils.dart | 17 +- lib/src/interface.dart | 2 +- lib/src/interface/error_code.dart | 780 ------------------ lib/src/interface/error_codes.dart | 582 +++++++++++++ lib/src/testing/core_matchers.dart | 2 +- test/chroot_test.dart | 2 +- test/common_tests.dart | 276 ++++--- 15 files changed, 870 insertions(+), 966 deletions(-) delete mode 100644 lib/src/interface/error_code.dart create mode 100644 lib/src/interface/error_codes.dart diff --git a/lib/src/backends/chroot/chroot_directory.dart b/lib/src/backends/chroot/chroot_directory.dart index 23d24c3..246c18c 100644 --- a/lib/src/backends/chroot/chroot_directory.dart +++ b/lib/src/backends/chroot/chroot_directory.dart @@ -30,18 +30,24 @@ class _ChrootDirectory extends _ChrootFileSystemEntity Future rename(String newPath) async { if (_isLink) { if (await fileSystem.type(path) != expectedType) { - throw new FileSystemException('Not a directory', path); + String msg = 'Not a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOTDIR)); } FileSystemEntityType type = await fileSystem.type(newPath); if (type != FileSystemEntityType.NOT_FOUND) { if (type != expectedType) { - throw new FileSystemException('Not a directory', newPath); + String msg = 'Not a directory'; + throw new FileSystemException( + msg, newPath, new OSError(msg, ErrorCodes.ENOTDIR)); } if (!(await fileSystem .directory(newPath) .list(followLinks: false) .isEmpty)) { - throw new FileSystemException('Directory not empty', newPath); + String msg = 'Directory not empty'; + throw new FileSystemException( + msg, newPath, new OSError(msg, ErrorCodes.ENOTEMPTY)); } } String target = await fileSystem.link(path).target(); @@ -58,18 +64,24 @@ class _ChrootDirectory extends _ChrootFileSystemEntity Directory renameSync(String newPath) { if (_isLink) { if (fileSystem.typeSync(path) != expectedType) { - throw new FileSystemException('Not a directory', path); + String msg = 'Not a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOTDIR)); } FileSystemEntityType type = fileSystem.typeSync(newPath); if (type != FileSystemEntityType.NOT_FOUND) { if (type != expectedType) { - throw new FileSystemException('Not a directory', newPath); + String msg = 'Not a directory'; + throw new FileSystemException( + msg, newPath, new OSError(msg, ErrorCodes.ENOTDIR)); } if (fileSystem .directory(newPath) .listSync(followLinks: false) .isNotEmpty) { - throw new FileSystemException('Directory not empty', newPath); + String msg = 'Directory not empty'; + throw new FileSystemException( + msg, newPath, new OSError(msg, ErrorCodes.ENOTEMPTY)); } } String target = fileSystem.link(path).targetSync(); @@ -99,9 +111,13 @@ class _ChrootDirectory extends _ChrootFileSystemEntity if (_isLink) { switch (await fileSystem.type(path)) { case FileSystemEntityType.NOT_FOUND: - throw new FileSystemException('No such file or directory', path); + String msg = 'No such file or directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOENT)); case FileSystemEntityType.FILE: - throw new FileSystemException('File exists', path); + String msg = 'File exists'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.EEXIST)); case FileSystemEntityType.DIRECTORY: // Nothing to do. return this; @@ -118,9 +134,13 @@ class _ChrootDirectory extends _ChrootFileSystemEntity if (_isLink) { switch (fileSystem.typeSync(path)) { case FileSystemEntityType.NOT_FOUND: - throw new FileSystemException('No such file or directory', path); + String msg = 'No such file or directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOENT)); case FileSystemEntityType.FILE: - throw new FileSystemException('File exists', path); + String msg = 'File exists'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.EEXIST)); case FileSystemEntityType.DIRECTORY: // Nothing to do. return; diff --git a/lib/src/backends/chroot/chroot_file.dart b/lib/src/backends/chroot/chroot_file.dart index 74d8cc9..8d72b47 100644 --- a/lib/src/backends/chroot/chroot_file.dart +++ b/lib/src/backends/chroot/chroot_file.dart @@ -45,7 +45,9 @@ class _ChrootFile extends _ChrootFileSystemEntity }; break; case FileSystemEntityType.DIRECTORY: - throw new FileSystemException('Is a directory', newPath); + String msg = 'Is a directory'; + throw new FileSystemException( + msg, newPath, new OSError(msg, ErrorCodes.EISDIR)); default: // Should never happen. throw new AssertionError(); @@ -55,9 +57,13 @@ class _ChrootFile extends _ChrootFileSystemEntity if (_isLink) { switch (await fileSystem.type(path)) { case FileSystemEntityType.NOT_FOUND: - throw new FileSystemException('No such file or directory', path); + String msg = 'No such file or directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOENT)); case FileSystemEntityType.DIRECTORY: - throw new FileSystemException('Is a directory', path); + String msg = 'Is a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.EISDIR)); case FileSystemEntityType.FILE: await setUp(); await fileSystem.delegate @@ -94,7 +100,9 @@ class _ChrootFile extends _ChrootFileSystemEntity }; break; case FileSystemEntityType.DIRECTORY: - throw new FileSystemException('Is a directory', newPath); + String msg = 'Is a directory'; + throw new FileSystemException( + msg, newPath, new OSError(msg, ErrorCodes.EISDIR)); default: // Should never happen. throw new AssertionError(); @@ -104,9 +112,13 @@ class _ChrootFile extends _ChrootFileSystemEntity if (_isLink) { switch (fileSystem.typeSync(path)) { case FileSystemEntityType.NOT_FOUND: - throw new FileSystemException('No such file or directory', path); + String msg = 'No such file or directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOENT)); case FileSystemEntityType.DIRECTORY: - throw new FileSystemException('Is a directory', path); + String msg = 'Is a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.EISDIR)); case FileSystemEntityType.FILE: setUp(); fileSystem.delegate @@ -149,7 +161,9 @@ class _ChrootFile extends _ChrootFileSystemEntity // Nothing to do. return this; case FileSystemEntityType.DIRECTORY: - throw new FileSystemException('Is a directory', path); + String msg = 'Is a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.EISDIR)); default: throw new AssertionError(); } @@ -181,7 +195,9 @@ class _ChrootFile extends _ChrootFileSystemEntity // Nothing to do. return; case FileSystemEntityType.DIRECTORY: - throw new FileSystemException('Is a directory', path); + String msg = 'Is a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.EISDIR)); default: throw new AssertionError(); } diff --git a/lib/src/backends/chroot/chroot_file_system.dart b/lib/src/backends/chroot/chroot_file_system.dart index d3c861b..1ff45e8 100644 --- a/lib/src/backends/chroot/chroot_file_system.dart +++ b/lib/src/backends/chroot/chroot_file_system.dart @@ -114,9 +114,13 @@ class ChrootFileSystem extends FileSystem { case FileSystemEntityType.DIRECTORY: break; case FileSystemEntityType.NOT_FOUND: - throw new FileSystemException('No such file or directory'); + String msg = 'No such file or directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOENT)); default: - throw new FileSystemException('Not a directory'); + String msg = 'Not a directory'; + throw new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOTDIR)); } assert(() { p.Context ctx = delegate.path; @@ -299,7 +303,9 @@ class ChrootFileSystem extends FileSystem { case FileSystemEntityType.FILE: breadcrumbs.clear(); if (parts.isNotEmpty) { - throw new FileSystemException('Not a directory', currentPath); + String msg = 'Not a directory'; + throw new FileSystemException( + msg, currentPath, new OSError(msg, ErrorCodes.ENOTDIR)); } break; case FileSystemEntityType.NOT_FOUND: @@ -309,7 +315,9 @@ class ChrootFileSystem extends FileSystem { } FileSystemException notFoundException() { - return new FileSystemException('No such file or directory', path); + String msg = 'No such file or directory'; + return new FileSystemException( + msg, path, new OSError(msg, ErrorCodes.ENOENT)); } switch (notFound) { @@ -334,8 +342,9 @@ class ChrootFileSystem extends FileSystem { break; } if (!breadcrumbs.add(currentPath)) { + String msg = 'Too many levels of symbolic links'; throw new FileSystemException( - 'Too many levels of symbolic links', path); + msg, path, new OSError(msg, ErrorCodes.ELOOP)); } String target = delegate.link(realPath).targetSync(); if (ctx.isAbsolute(target)) { diff --git a/lib/src/backends/chroot/chroot_file_system_entity.dart b/lib/src/backends/chroot/chroot_file_system_entity.dart index 89b1487..7ec04f7 100644 --- a/lib/src/backends/chroot/chroot_file_system_entity.dart +++ b/lib/src/backends/chroot/chroot_file_system_entity.dart @@ -116,10 +116,16 @@ abstract class _ChrootFileSystemEntity const _LinuxErrorCodes(); - - /// TODO - static ErrorCodes get macos => const _MacosErrorCodes(); - - /// Operation not permitted - int get EPERM; // ignore: non_constant_identifier_names - - /// No such file or directory - int get ENOENT; // ignore: non_constant_identifier_names - - /// No such process - int get ESRCH; // ignore: non_constant_identifier_names - - /// Interrupted system call - int get EINTR; // ignore: non_constant_identifier_names - - /// I/O error - int get EIO; // ignore: non_constant_identifier_names - - /// No such device or address - int get ENXIO; // ignore: non_constant_identifier_names - - /// Argument list too long - int get E2BIG; // ignore: non_constant_identifier_names - - /// Exec format error - int get ENOEXEC; // ignore: non_constant_identifier_names - - /// Bad file number - int get EBADF; // ignore: non_constant_identifier_names - - /// No child processes - int get ECHILD; // ignore: non_constant_identifier_names - - /// Try again - int get EAGAIN; // ignore: non_constant_identifier_names - - /// Out of memory - int get ENOMEM; // ignore: non_constant_identifier_names - - /// Permission denied - int get EACCES; // ignore: non_constant_identifier_names - - /// Bad address - int get EFAULT; // ignore: non_constant_identifier_names - - /// Block device required - int get ENOTBLK; // ignore: non_constant_identifier_names - - /// Device or resource busy - int get EBUSY; // ignore: non_constant_identifier_names - - /// File exists - int get EEXIST; // ignore: non_constant_identifier_names - - /// Cross-device link - int get EXDEV; // ignore: non_constant_identifier_names - - /// No such device - int get ENODEV; // ignore: non_constant_identifier_names - - /// Not a directory - int get ENOTDIR; // ignore: non_constant_identifier_names - - /// Is a directory - int get EISDIR; // ignore: non_constant_identifier_names - - /// Invalid argument - int get EINVAL; // ignore: non_constant_identifier_names - - /// File table overflow - int get ENFILE; // ignore: non_constant_identifier_names - - /// Too many open files - int get EMFILE; // ignore: non_constant_identifier_names - - /// Not a typewriter - int get ENOTTY; // ignore: non_constant_identifier_names - - /// Text file busy - int get ETXTBSY; // ignore: non_constant_identifier_names - - /// File too large - int get EFBIG; // ignore: non_constant_identifier_names - - /// No space left on device - int get ENOSPC; // ignore: non_constant_identifier_names - - /// Illegal seek - int get ESPIPE; // ignore: non_constant_identifier_names - - /// Read-only file system - int get EROFS; // ignore: non_constant_identifier_names - - /// Too many links - int get EMLINK; // ignore: non_constant_identifier_names - - /// Broken pipe - int get EPIPE; // ignore: non_constant_identifier_names - - /// Math argument out of domain of func - int get EDOM; // ignore: non_constant_identifier_names - - /// Math result not representable - int get ERANGE; // ignore: non_constant_identifier_names - - /// File name too long - int get ENAMETOOLONG; // ignore: non_constant_identifier_names - - /// No record locks available - int get ENOLCK; // ignore: non_constant_identifier_names - - /// Function not implemented - int get ENOSYS; // ignore: non_constant_identifier_names - - /// Directory not empty - int get ENOTEMPTY; // ignore: non_constant_identifier_names - - /// Too many symbolic links encountered - int get ELOOP; // ignore: non_constant_identifier_names - - /// Operation would block - int get EWOULDBLOCK; // ignore: non_constant_identifier_names - - /// No message of desired type - int get ENOMSG; // ignore: non_constant_identifier_names - - /// Identifier removed - int get EIDRM; // ignore: non_constant_identifier_names - - /// Device not a stream - int get ENOSTR; // ignore: non_constant_identifier_names - - /// No data available - int get ENODATA; // ignore: non_constant_identifier_names - - /// Timer expired - int get ETIME; // ignore: non_constant_identifier_names - - /// Out of streams resources - int get ENOSR; // ignore: non_constant_identifier_names - - /// Object is remote - int get EREMOTE; // ignore: non_constant_identifier_names - - /// Link has been severed - int get ENOLINK; // ignore: non_constant_identifier_names - - /// Protocol error - int get EPROTO; // ignore: non_constant_identifier_names - - /// Multihop attempted - int get EMULTIHOP; // ignore: non_constant_identifier_names - - /// Not a data message - int get EBADMSG; // ignore: non_constant_identifier_names - - /// Value too large for defined data type - int get EOVERFLOW; // ignore: non_constant_identifier_names - - /// Illegal byte sequence - int get EILSEQ; // ignore: non_constant_identifier_names - - /// Too many users - int get EUSERS; // ignore: non_constant_identifier_names - - /// Socket operation on non-socket - int get ENOTSOCK; // ignore: non_constant_identifier_names - - /// Destination address required - int get EDESTADDRREQ; // ignore: non_constant_identifier_names - - /// Message too long - int get EMSGSIZE; // ignore: non_constant_identifier_names - - /// Protocol wrong type for socket - int get EPROTOTYPE; // ignore: non_constant_identifier_names - - /// Protocol not available - int get ENOPROTOOPT; // ignore: non_constant_identifier_names - - /// Protocol not supported - int get EPROTONOSUPPORT; // ignore: non_constant_identifier_names - - /// Socket type not supported - int get ESOCKTNOSUPPORT; // ignore: non_constant_identifier_names - - /// Protocol family not supported - int get EPFNOSUPPORT; // ignore: non_constant_identifier_names - - /// Address family not supported by protocol - int get EAFNOSUPPORT; // ignore: non_constant_identifier_names - - /// Address already in use - int get EADDRINUSE; // ignore: non_constant_identifier_names - - /// Cannot assign requested address - int get EADDRNOTAVAIL; // ignore: non_constant_identifier_names - - /// Network is down - int get ENETDOWN; // ignore: non_constant_identifier_names - - /// Network is unreachable - int get ENETUNREACH; // ignore: non_constant_identifier_names - - /// Network dropped connection because of reset - int get ENETRESET; // ignore: non_constant_identifier_names - - /// Software caused connection abort - int get ECONNABORTED; // ignore: non_constant_identifier_names - - /// Connection reset by peer - int get ECONNRESET; // ignore: non_constant_identifier_names - - /// No buffer space available - int get ENOBUFS; // ignore: non_constant_identifier_names - - /// Transport endpoint is already connected - int get EISCONN; // ignore: non_constant_identifier_names - - /// Transport endpoint is not connected - int get ENOTCONN; // ignore: non_constant_identifier_names - - /// Cannot send after transport endpoint shutdown - int get ESHUTDOWN; // ignore: non_constant_identifier_names - - /// Too many references: cannot splice - int get ETOOMANYREFS; // ignore: non_constant_identifier_names - - /// Connection timed out - int get ETIMEDOUT; // ignore: non_constant_identifier_names - - /// Connection refused - int get ECONNREFUSED; // ignore: non_constant_identifier_names - - /// Host is down - int get EHOSTDOWN; // ignore: non_constant_identifier_names - - /// No route to host - int get EHOSTUNREACH; // ignore: non_constant_identifier_names - - /// Operation already in progress - int get EALREADY; // ignore: non_constant_identifier_names - - /// Operation now in progress - int get EINPROGRESS; // ignore: non_constant_identifier_names - - /// Stale NFS file handle - int get ESTALE; // ignore: non_constant_identifier_names - - /// Quota exceeded - int get EDQUOT; // ignore: non_constant_identifier_names - - /// Operation Canceled - int get ECANCELED; // ignore: non_constant_identifier_names -} - -class _LinuxErrorCodes implements ErrorCodes { - const _LinuxErrorCodes(); - - @override - final int EPERM = 1; // ignore: non_constant_identifier_names - - @override - final int ENOENT = 2; // ignore: non_constant_identifier_names - - @override - final int ESRCH = 3; // ignore: non_constant_identifier_names - - @override - final int EINTR = 4; // ignore: non_constant_identifier_names - - @override - final int EIO = 5; // ignore: non_constant_identifier_names - - @override - final int ENXIO = 6; // ignore: non_constant_identifier_names - - @override - final int E2BIG = 7; // ignore: non_constant_identifier_names - - @override - final int ENOEXEC = 8; // ignore: non_constant_identifier_names - - @override - final int EBADF = 9; // ignore: non_constant_identifier_names - - @override - final int ECHILD = 10; // ignore: non_constant_identifier_names - - @override - final int EAGAIN = 11; // ignore: non_constant_identifier_names - - @override - final int ENOMEM = 12; // ignore: non_constant_identifier_names - - @override - final int EACCES = 13; // ignore: non_constant_identifier_names - - @override - final int EFAULT = 14; // ignore: non_constant_identifier_names - - @override - final int ENOTBLK = 15; // ignore: non_constant_identifier_names - - @override - final int EBUSY = 16; // ignore: non_constant_identifier_names - - @override - final int EEXIST = 17; // ignore: non_constant_identifier_names - - @override - final int EXDEV = 18; // ignore: non_constant_identifier_names - - @override - final int ENODEV = 19; // ignore: non_constant_identifier_names - - @override - final int ENOTDIR = 20; // ignore: non_constant_identifier_names - - @override - final int EISDIR = 21; // ignore: non_constant_identifier_names - - @override - final int EINVAL = 22; // ignore: non_constant_identifier_names - - @override - final int ENFILE = 23; // ignore: non_constant_identifier_names - - @override - final int EMFILE = 24; // ignore: non_constant_identifier_names - - @override - final int ENOTTY = 25; // ignore: non_constant_identifier_names - - @override - final int ETXTBSY = 26; // ignore: non_constant_identifier_names - - @override - final int EFBIG = 27; // ignore: non_constant_identifier_names - - @override - final int ENOSPC = 28; // ignore: non_constant_identifier_names - - @override - final int ESPIPE = 29; // ignore: non_constant_identifier_names - - @override - final int EROFS = 30; // ignore: non_constant_identifier_names - - @override - final int EMLINK = 31; // ignore: non_constant_identifier_names - - @override - final int EPIPE = 32; // ignore: non_constant_identifier_names - - @override - final int EDOM = 33; // ignore: non_constant_identifier_names - - @override - final int ERANGE = 34; // ignore: non_constant_identifier_names - - @override - final int ENAMETOOLONG = 36; // ignore: non_constant_identifier_names - - @override - final int ENOLCK = 37; // ignore: non_constant_identifier_names - - @override - final int ENOSYS = 38; // ignore: non_constant_identifier_names - - @override - final int ENOTEMPTY = 39; // ignore: non_constant_identifier_names - - @override - final int ELOOP = 40; // ignore: non_constant_identifier_names - - @override - final int EWOULDBLOCK = 11/*EAGAIN*/; // ignore: non_constant_identifier_names - - @override - final int ENOMSG = 42; // ignore: non_constant_identifier_names - - @override - final int EIDRM = 43; // ignore: non_constant_identifier_names - - @override - final int ENOSTR = 60; // ignore: non_constant_identifier_names - - @override - final int ENODATA = 61; // ignore: non_constant_identifier_names - - @override - final int ETIME = 62; // ignore: non_constant_identifier_names - - @override - final int ENOSR = 63; // ignore: non_constant_identifier_names - - @override - final int EREMOTE = 66; // ignore: non_constant_identifier_names - - @override - final int ENOLINK = 67; // ignore: non_constant_identifier_names - - @override - final int EPROTO = 71; // ignore: non_constant_identifier_names - - @override - final int EMULTIHOP = 72; // ignore: non_constant_identifier_names - - @override - final int EBADMSG = 74; // ignore: non_constant_identifier_names - - @override - final int EOVERFLOW = 75; // ignore: non_constant_identifier_names - - @override - final int EILSEQ = 84; // ignore: non_constant_identifier_names - - @override - final int EUSERS = 87; // ignore: non_constant_identifier_names - - @override - final int ENOTSOCK = 88; // ignore: non_constant_identifier_names - - @override - final int EDESTADDRREQ = 89; // ignore: non_constant_identifier_names - - @override - final int EMSGSIZE = 90; // ignore: non_constant_identifier_names - - @override - final int EPROTOTYPE = 91; // ignore: non_constant_identifier_names - - @override - final int ENOPROTOOPT = 92; // ignore: non_constant_identifier_names - - @override - final int EPROTONOSUPPORT = 93; // ignore: non_constant_identifier_names - - @override - final int ESOCKTNOSUPPORT = 94; // ignore: non_constant_identifier_names - - @override - final int EPFNOSUPPORT = 96; // ignore: non_constant_identifier_names - - @override - final int EAFNOSUPPORT = 97; // ignore: non_constant_identifier_names - - @override - final int EADDRINUSE = 98; // ignore: non_constant_identifier_names - - @override - final int EADDRNOTAVAIL = 99; // ignore: non_constant_identifier_names - - @override - final int ENETDOWN = 100; // ignore: non_constant_identifier_names - - @override - final int ENETUNREACH = 101; // ignore: non_constant_identifier_names - - @override - final int ENETRESET = 102; // ignore: non_constant_identifier_names - - @override - final int ECONNABORTED = 103; // ignore: non_constant_identifier_names - - @override - final int ECONNRESET = 104; // ignore: non_constant_identifier_names - - @override - final int ENOBUFS = 105; // ignore: non_constant_identifier_names - - @override - final int EISCONN = 106; // ignore: non_constant_identifier_names - - @override - final int ENOTCONN = 107; // ignore: non_constant_identifier_names - - @override - final int ESHUTDOWN = 108; // ignore: non_constant_identifier_names - - @override - final int ETOOMANYREFS = 109; // ignore: non_constant_identifier_names - - @override - final int ETIMEDOUT = 110; // ignore: non_constant_identifier_names - - @override - final int ECONNREFUSED = 111; // ignore: non_constant_identifier_names - - @override - final int EHOSTDOWN = 112; // ignore: non_constant_identifier_names - - @override - final int EHOSTUNREACH = 113; // ignore: non_constant_identifier_names - - @override - final int EALREADY = 114; // ignore: non_constant_identifier_names - - @override - final int EINPROGRESS = 115; // ignore: non_constant_identifier_names - - @override - final int ESTALE = 116; // ignore: non_constant_identifier_names - - @override - final int EDQUOT = 122; // ignore: non_constant_identifier_names - - @override - final int ECANCELED = 125; // ignore: non_constant_identifier_names -} - -class _MacosErrorCodes implements ErrorCodes { - const _MacosErrorCodes(); - - @override - final int EPERM = 1; // ignore: non_constant_identifier_names - - @override - final int ENOENT = 2; // ignore: non_constant_identifier_names - - @override - final int ESRCH = 3; // ignore: non_constant_identifier_names - - @override - final int EINTR = 4; // ignore: non_constant_identifier_names - - @override - final int EIO = 5; // ignore: non_constant_identifier_names - - @override - final int ENXIO = 6; // ignore: non_constant_identifier_names - - @override - final int E2BIG = 7; // ignore: non_constant_identifier_names - - @override - final int ENOEXEC = 8; // ignore: non_constant_identifier_names - - @override - final int EBADF = 9; // ignore: non_constant_identifier_names - - @override - final int ECHILD = 10; // ignore: non_constant_identifier_names - - @override - final int ENOMEM = 12; // ignore: non_constant_identifier_names - - @override - final int EACCES = 13; // ignore: non_constant_identifier_names - - @override - final int EFAULT = 14; // ignore: non_constant_identifier_names - - @override - final int ENOTBLK = 15; // ignore: non_constant_identifier_names - - @override - final int EBUSY = 16; // ignore: non_constant_identifier_names - - @override - final int EEXIST = 17; // ignore: non_constant_identifier_names - - @override - final int EXDEV = 18; // ignore: non_constant_identifier_names - - @override - final int ENODEV = 19; // ignore: non_constant_identifier_names - - @override - final int ENOTDIR = 20; // ignore: non_constant_identifier_names - - @override - final int EISDIR = 21; // ignore: non_constant_identifier_names - - @override - final int EINVAL = 22; // ignore: non_constant_identifier_names - - @override - final int ENFILE = 23; // ignore: non_constant_identifier_names - - @override - final int EMFILE = 24; // ignore: non_constant_identifier_names - - @override - final int ENOTTY = 25; // ignore: non_constant_identifier_names - - @override - final int ETXTBSY = 26; // ignore: non_constant_identifier_names - - @override - final int EFBIG = 27; // ignore: non_constant_identifier_names - - @override - final int ENOSPC = 28; // ignore: non_constant_identifier_names - - @override - final int ESPIPE = 29; // ignore: non_constant_identifier_names - - @override - final int EROFS = 30; // ignore: non_constant_identifier_names - - @override - final int EMLINK = 31; // ignore: non_constant_identifier_names - - @override - final int EPIPE = 32; // ignore: non_constant_identifier_names - - @override - final int EDOM = 33; // ignore: non_constant_identifier_names - - @override - final int ERANGE = 34; // ignore: non_constant_identifier_names - - @override - final int EAGAIN = 35; // ignore: non_constant_identifier_names - - @override - final int EWOULDBLOCK = 35 /*EAGAIN*/; // ignore: non_constant_identifier_names - - @override - final int EINPROGRESS = 36; // ignore: non_constant_identifier_names - - @override - final int EALREADY = 37; // ignore: non_constant_identifier_names - - @override - final int ENOTSOCK = 38; // ignore: non_constant_identifier_names - - @override - final int EDESTADDRREQ = 39; // ignore: non_constant_identifier_names - - @override - final int EMSGSIZE = 40; // ignore: non_constant_identifier_names - - @override - final int EPROTOTYPE = 41; // ignore: non_constant_identifier_names - - @override - final int ENOPROTOOPT = 42; // ignore: non_constant_identifier_names - - @override - final int EPROTONOSUPPORT = 43; // ignore: non_constant_identifier_names - - @override - final int ESOCKTNOSUPPORT = 44; // ignore: non_constant_identifier_names - - @override - final int EPFNOSUPPORT = 46; // ignore: non_constant_identifier_names - - @override - final int EAFNOSUPPORT = 47; // ignore: non_constant_identifier_names - - @override - final int EADDRINUSE = 48; // ignore: non_constant_identifier_names - - @override - final int EADDRNOTAVAIL = 49; // ignore: non_constant_identifier_names - - @override - final int ENETDOWN = 50; // ignore: non_constant_identifier_names - - @override - final int ENETUNREACH = 51; // ignore: non_constant_identifier_names - - @override - final int ENETRESET = 52; // ignore: non_constant_identifier_names - - @override - final int ECONNABORTED = 53; // ignore: non_constant_identifier_names - - @override - final int ECONNRESET = 54; // ignore: non_constant_identifier_names - - @override - final int ENOBUFS = 55; // ignore: non_constant_identifier_names - - @override - final int EISCONN = 56; // ignore: non_constant_identifier_names - - @override - final int ENOTCONN = 57; // ignore: non_constant_identifier_names - - @override - final int ESHUTDOWN = 58; // ignore: non_constant_identifier_names - - @override - final int ETOOMANYREFS = 59; // ignore: non_constant_identifier_names - - @override - final int ETIMEDOUT = 60; // ignore: non_constant_identifier_names - - @override - final int ECONNREFUSED = 61; // ignore: non_constant_identifier_names - - @override - final int ELOOP = 62; // ignore: non_constant_identifier_names - - @override - final int ENAMETOOLONG = 63; // ignore: non_constant_identifier_names - - @override - final int EHOSTDOWN = 64; // ignore: non_constant_identifier_names - - @override - final int EHOSTUNREACH = 65; // ignore: non_constant_identifier_names - - @override - final int ENOTEMPTY = 66; // ignore: non_constant_identifier_names - - @override - final int EUSERS = 68; // ignore: non_constant_identifier_names - - @override - final int EDQUOT = 69; // ignore: non_constant_identifier_names - - @override - final int ESTALE = 70; // ignore: non_constant_identifier_names - - @override - final int EREMOTE = 71; // ignore: non_constant_identifier_names - - @override - final int ENOLCK = 77; // ignore: non_constant_identifier_names - - @override - final int ENOSYS = 78; // ignore: non_constant_identifier_names - - @override - final int EOVERFLOW = 84; // ignore: non_constant_identifier_names - - @override - final int ECANCELED = 89; // ignore: non_constant_identifier_names - - @override - final int EIDRM = 90; // ignore: non_constant_identifier_names - - @override - final int ENOMSG = 91; // ignore: non_constant_identifier_names - - @override - final int EILSEQ = 92; // ignore: non_constant_identifier_names - - @override - final int EBADMSG = 94; // ignore: non_constant_identifier_names - - @override - final int EMULTIHOP = 95; // ignore: non_constant_identifier_names - - @override - final int ENODATA = 96; // ignore: non_constant_identifier_names - - @override - final int ENOLINK = 97; // ignore: non_constant_identifier_names - - @override - final int ENOSR = 98; // ignore: non_constant_identifier_names - - @override - final int ENOSTR = 99; // ignore: non_constant_identifier_names - - @override - final int EPROTO = 100; // ignore: non_constant_identifier_names - - @override - final int ETIME = 101; // ignore: non_constant_identifier_names -} diff --git a/lib/src/interface/error_codes.dart b/lib/src/interface/error_codes.dart new file mode 100644 index 0000000..357cedd --- /dev/null +++ b/lib/src/interface/error_codes.dart @@ -0,0 +1,582 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +part of file.src.interface; + +/// Operating system error codes. +class ErrorCodes { + ErrorCodes._(); + + /// Argument list too long + // ignore: non_constant_identifier_names + static int get E2BIG => _platform((_Codes codes) => codes.e2big); + + /// Permission denied + // ignore: non_constant_identifier_names + static int get EACCES => _platform((_Codes codes) => codes.eacces); + + /// Try again + // ignore: non_constant_identifier_names + static int get EAGAIN => _platform((_Codes codes) => codes.eagain); + + /// Bad file number + // ignore: non_constant_identifier_names + static int get EBADF => _platform((_Codes codes) => codes.ebadf); + + /// Device or resource busy + // ignore: non_constant_identifier_names + static int get EBUSY => _platform((_Codes codes) => codes.ebusy); + + /// No child processes + // ignore: non_constant_identifier_names + static int get ECHILD => _platform((_Codes codes) => codes.echild); + + /// Resource deadlock would occur + // ignore: non_constant_identifier_names + static int get EDEADLK => _platform((_Codes codes) => codes.edeadlk); + + /// Math argument out of domain of func + // ignore: non_constant_identifier_names + static int get EDOM => _platform((_Codes codes) => codes.edom); + + /// File exists + // ignore: non_constant_identifier_names + static int get EEXIST => _platform((_Codes codes) => codes.eexist); + + /// Bad address + // ignore: non_constant_identifier_names + static int get EFAULT => _platform((_Codes codes) => codes.efault); + + /// File too large + // ignore: non_constant_identifier_names + static int get EFBIG => _platform((_Codes codes) => codes.efbig); + + /// Illegal byte sequence + // ignore: non_constant_identifier_names + static int get EILSEQ => _platform((_Codes codes) => codes.eilseq); + + /// Interrupted system call + // ignore: non_constant_identifier_names + static int get EINTR => _platform((_Codes codes) => codes.eintr); + + /// Invalid argument + // ignore: non_constant_identifier_names + static int get EINVAL => _platform((_Codes codes) => codes.einval); + + /// I/O error + // ignore: non_constant_identifier_names + static int get EIO => _platform((_Codes codes) => codes.eio); + + /// Is a directory + // ignore: non_constant_identifier_names + static int get EISDIR => _platform((_Codes codes) => codes.eisdir); + + /// Too many levels of symbolic links + // ignore: non_constant_identifier_names + static int get ELOOP => _platform((_Codes codes) => codes.eloop); + + /// Too many open files + // ignore: non_constant_identifier_names + static int get EMFILE => _platform((_Codes codes) => codes.emfile); + + /// Too many links + // ignore: non_constant_identifier_names + static int get EMLINK => _platform((_Codes codes) => codes.emlink); + + /// File name too long + // ignore: non_constant_identifier_names + static int get ENAMETOOLONG => _platform((_Codes codes) => codes.enametoolong); + + /// File table overflow + // ignore: non_constant_identifier_names + static int get ENFILE => _platform((_Codes codes) => codes.enfile); + + /// No such device + // ignore: non_constant_identifier_names + static int get ENODEV => _platform((_Codes codes) => codes.enodev); + + /// No such file or directory + // ignore: non_constant_identifier_names + static int get ENOENT => _platform((_Codes codes) => codes.enoent); + + /// Exec format error + // ignore: non_constant_identifier_names + static int get ENOEXEC => _platform((_Codes codes) => codes.enoexec); + + /// No record locks available + // ignore: non_constant_identifier_names + static int get ENOLCK => _platform((_Codes codes) => codes.enolck); + + /// Out of memory + // ignore: non_constant_identifier_names + static int get ENOMEM => _platform((_Codes codes) => codes.enomem); + + /// No space left on device + // ignore: non_constant_identifier_names + static int get ENOSPC => _platform((_Codes codes) => codes.enospc); + + /// Function not implemented + // ignore: non_constant_identifier_names + static int get ENOSYS => _platform((_Codes codes) => codes.enosys); + + /// Not a directory + // ignore: non_constant_identifier_names + static int get ENOTDIR => _platform((_Codes codes) => codes.enotdir); + + /// Directory not empty + // ignore: non_constant_identifier_names + static int get ENOTEMPTY => _platform((_Codes codes) => codes.enotempty); + + /// Not a typewriter + // ignore: non_constant_identifier_names + static int get ENOTTY => _platform((_Codes codes) => codes.enotty); + + /// No such device or address + // ignore: non_constant_identifier_names + static int get ENXIO => _platform((_Codes codes) => codes.enxio); + + /// Operation not permitted + // ignore: non_constant_identifier_names + static int get EPERM => _platform((_Codes codes) => codes.eperm); + + /// Broken pipe + // ignore: non_constant_identifier_names + static int get EPIPE => _platform((_Codes codes) => codes.epipe); + + /// Math result not representable + // ignore: non_constant_identifier_names + static int get ERANGE => _platform((_Codes codes) => codes.erange); + + /// Read-only file system + // ignore: non_constant_identifier_names + static int get EROFS => _platform((_Codes codes) => codes.erofs); + + /// Illegal seek + // ignore: non_constant_identifier_names + static int get ESPIPE => _platform((_Codes codes) => codes.espipe); + + /// No such process + // ignore: non_constant_identifier_names + static int get ESRCH => _platform((_Codes codes) => codes.esrch); + + /// Cross-device link + // ignore: non_constant_identifier_names + static int get EXDEV => _platform((_Codes codes) => codes.exdev); + + static int _platform(int getCode(_Codes codes)) { + _Codes codes = _platforms['macos']; // TODO(tvolkert): switch on platform + return getCode(codes); + } +} + +const Map _platforms = const { + 'linux': const _LinuxCodes(), + 'macos': const _MacOSCodes(), + 'windows': const _WindowsCodes(), +}; + +abstract class _Codes { + int get e2big; + int get eacces; + int get eagain; + int get ebadf; + int get ebusy; + int get echild; + int get edeadlk; + int get edom; + int get eexist; + int get efault; + int get efbig; + int get eilseq; + int get eintr; + int get einval; + int get eio; + int get eisdir; + int get eloop; + int get emfile; + int get emlink; + int get enametoolong; + int get enfile; + int get enodev; + int get enoent; + int get enoexec; + int get enolck; + int get enomem; + int get enospc; + int get enosys; + int get enotdir; + int get enotempty; + int get enotty; + int get enxio; + int get eperm; + int get epipe; + int get erange; + int get erofs; + int get espipe; + int get esrch; + int get exdev; +} + +class _LinuxCodes implements _Codes { + const _LinuxCodes(); + + @override + final int e2big = 7; + + @override + final int eacces = 13; + + @override + final int eagain = 11; + + @override + final int ebadf = 9; + + @override + final int ebusy = 16; + + @override + final int echild = 10; + + @override + final int edeadlk = 35; + + @override + final int edom = 33; + + @override + final int eexist = 17; + + @override + final int efault = 14; + + @override + final int efbig = 27; + + @override + final int eilseq = 84; + + @override + final int eintr = 4; + + @override + final int einval = 22; + + @override + final int eio = 5; + + @override + final int eisdir = 21; + + @override + final int eloop = 40; + + @override + final int emfile = 24; + + @override + final int emlink = 31; + + @override + final int enametoolong = 36; + + @override + final int enfile = 23; + + @override + final int enodev = 19; + + @override + final int enoent = 2; + + @override + final int enoexec = 8; + + @override + final int enolck = 37; + + @override + final int enomem = 12; + + @override + final int enospc = 28; + + @override + final int enosys = 38; + + @override + final int enotdir = 20; + + @override + final int enotempty = 39; + + @override + final int enotty = 25; + + @override + final int enxio = 6; + + @override + final int eperm = 1; + + @override + final int epipe = 32; + + @override + final int erange = 34; + + @override + final int erofs = 30; + + @override + final int espipe = 29; + + @override + final int esrch = 3; + + @override + final int exdev = 18; +} + +class _MacOSCodes implements _Codes { + const _MacOSCodes(); + + @override + final int e2big = 7; + + @override + final int eacces = 13; + + @override + final int eagain = 35; + + @override + final int ebadf = 9; + + @override + final int ebusy = 16; + + @override + final int echild = 10; + + @override + final int edeadlk = 11; + + @override + final int edom = 33; + + @override + final int eexist = 17; + + @override + final int efault = 14; + + @override + final int efbig = 27; + + @override + final int eilseq = 92; + + @override + final int eintr = 4; + + @override + final int einval = 22; + + @override + final int eio = 5; + + @override + final int eisdir = 21; + + @override + final int eloop = 62; + + @override + final int emfile = 24; + + @override + final int emlink = 31; + + @override + final int enametoolong = 63; + + @override + final int enfile = 23; + + @override + final int enodev = 19; + + @override + final int enoent = 2; + + @override + final int enoexec = 8; + + @override + final int enolck = 77; + + @override + final int enomem = 12; + + @override + final int enospc = 28; + + @override + final int enosys = 78; + + @override + final int enotdir = 20; + + @override + final int enotempty = 66; + + @override + final int enotty = 25; + + @override + final int enxio = 6; + + @override + final int eperm = 1; + + @override + final int epipe = 32; + + @override + final int erange = 34; + + @override + final int erofs = 30; + + @override + final int espipe = 29; + + @override + final int esrch = 3; + + @override + final int exdev = 18; +} + +class _WindowsCodes implements _Codes { + const _WindowsCodes(); + + @override + final int e2big = 7; + + @override + final int eacces = 13; + + @override + final int eagain = 11; + + @override + final int ebadf = 9; + + @override + final int ebusy = 16; + + @override + final int echild = 10; + + @override + final int edeadlk = 36; + + @override + final int edom = 33; + + @override + final int eexist = 17; + + @override + final int efault = 14; + + @override + final int efbig = 27; + + @override + final int eilseq = 42; + + @override + final int eintr = 4; + + @override + final int einval = 22; + + @override + final int eio = 5; + + @override + final int eisdir = 21; + + @override + final int eloop = -1; + + @override + final int emfile = 24; + + @override + final int emlink = 31; + + @override + final int enametoolong = 38; + + @override + final int enfile = 23; + + @override + final int enodev = 19; + + @override + final int enoent = 2; + + @override + final int enoexec = 8; + + @override + final int enolck = 39; + + @override + final int enomem = 12; + + @override + final int enospc = 28; + + @override + final int enosys = 40; + + @override + final int enotdir = 20; + + @override + final int enotempty = 41; + + @override + final int enotty = 25; + + @override + final int enxio = 6; + + @override + final int eperm = 1; + + @override + final int epipe = 32; + + @override + final int erange = 34; + + @override + final int erofs = 30; + + @override + final int espipe = 29; + + @override + final int esrch = 3; + + @override + final int exdev = 18; +} diff --git a/lib/src/testing/core_matchers.dart b/lib/src/testing/core_matchers.dart index eabbaab..502afd1 100644 --- a/lib/src/testing/core_matchers.dart +++ b/lib/src/testing/core_matchers.dart @@ -57,7 +57,7 @@ Matcher throwsFileSystemException([dynamic osErrorCode]) => /// is an `int`, it will be wrapped in an equality matcher. /// /// See also: -/// - [ErrorCode] +/// - [ErrorCodes] void expectFileSystemException(dynamic osErrorCode, void callback()) { expect(callback, throwsFileSystemException(osErrorCode)); } diff --git a/test/chroot_test.dart b/test/chroot_test.dart index f9e0d62..b911e19 100644 --- a/test/chroot_test.dart +++ b/test/chroot_test.dart @@ -104,7 +104,7 @@ void main() { test('throwsIfSetToSymlinkToDirectoryOutsideJail', () { mem.directory('/bar').createSync(); mem.link('/tmp/foo').createSync('/bar'); - expectFileSystemException('No such file or directory', () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.currentDirectory = '/foo'; }); }); diff --git a/test/common_tests.dart b/test/common_tests.dart index 1b2e19f..6079de4 100644 --- a/test/common_tests.dart +++ b/test/common_tests.dart @@ -227,14 +227,14 @@ void runCommonTests( }); test('throwsIfSetToNonExistentPath', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.currentDirectory = ns('/foo'); }); }); test('throwsIfHasNonExistentPathInComplexChain', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.currentDirectory = ns('/bar/../foo'); }); }); @@ -295,14 +295,14 @@ void runCommonTests( test('throwsIfSetToFilePathSegmentAtTail', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.currentDirectory = ns('/foo'); }); }); test('throwsIfSetToFilePathSegmentViaTraversal', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.currentDirectory = ns('/foo/bar/baz'); }); }); @@ -325,9 +325,10 @@ void runCommonTests( test('throwsIfSetToLinkLoop', () { fs.link(ns('/foo')).createSync(ns('/bar')); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.ETIME, () { - fs.currentDirectory = ns('/foo'); - }); + expectFileSystemException( + anyOf(ErrorCodes.EMLINK, ErrorCodes.ELOOP), + () => fs.currentDirectory = ns('/foo'), + ); }); }); @@ -395,14 +396,14 @@ void runCommonTests( }); test('throwsForDifferentPathsToNonExistentEntities', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.identicalSync(ns('/foo'), ns('/bar')); }); }); test('throwsForDifferentPathsToOneFileOneNonExistentEntity', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.identicalSync(ns('/foo'), ns('/bar')); }); }); @@ -519,7 +520,7 @@ void runCommonTests( test('throwsIfAlreadyExistsAsFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.directory(ns('/foo')).createSync(); }); }); @@ -533,21 +534,24 @@ void runCommonTests( test('throwsIfAlreadyExistsAsLinkToFile', () { fs.file(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { - fs.directory(ns('/bar')).createSync(); - }); + // TODO(tvolkert): Change this to just be 'Not a directory' + // once Dart 1.22 is stable. + expectFileSystemException( + anyOf(ErrorCodes.EEXIST, ErrorCodes.ENOTDIR), + () => fs.directory(ns('/bar')).createSync(), + ); }); test('throwsIfAlreadyExistsAsLinkToNotFoundAtTail', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).createSync(); }); }); test('throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal', () { fs.link(ns('/foo')).createSync(ns('/bar/baz')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).createSync(); }); }); @@ -556,7 +560,7 @@ void runCommonTests( fs.directory(ns('/foo')).createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/bar/baz')).createSync(ns('/foo/qux')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/bar/baz')).createSync(); }); }); @@ -568,7 +572,7 @@ void runCommonTests( }); test('throwsIfAncestorDoesntExistRecursiveFalse', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo/bar')).createSync(); }); }); @@ -605,14 +609,14 @@ void runCommonTests( test('throwsIfDestinationIsFile', () { fs.file(ns('/bar')).createSync(); Directory src = fs.directory(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { src.renameSync(ns('/bar')); }); }); test('throwsIfDestinationParentFolderDoesntExist', () { Directory src = fs.directory(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { src.renameSync(ns('/bar/baz')); }); }); @@ -621,20 +625,20 @@ void runCommonTests( fs.file(ns('/bar/baz')).createSync(recursive: true); Directory src = fs.directory(ns('/foo'))..createSync(); expectFileSystemException( - anyOf(ErrorCodes.macos.ENOTEMPTY, ErrorCodes.linux.EEXIST), + anyOf(ErrorCodes.ENOTEMPTY, ErrorCodes.EEXIST), () => src.renameSync(ns('/bar')), ); }); test('throwsIfSourceDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceIsFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.directory(ns('/foo')).renameSync(ns('/bar')); }); }); @@ -654,7 +658,7 @@ void runCommonTests( test('throwsIfDestinationIsLinkToNotFound', () { Directory src = fs.directory(ns('/foo'))..createSync(); fs.link(ns('/bar')).createSync(ns('/baz')); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { src.renameSync(ns('/bar')); }); }); @@ -663,7 +667,7 @@ void runCommonTests( Directory src = fs.directory(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/baz')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { src.renameSync(ns('/baz')); }); }); @@ -712,10 +716,9 @@ void runCommonTests( test('throwsIfNonEmptyDirectoryExistsAndRecursiveFalse', () { Directory dir = fs.directory(ns('/foo'))..createSync(); fs.file(ns('/foo/bar')).createSync(); - expectFileSystemException( - anyOf(ErrorCodes.linux.ENOTEMPTY, ErrorCodes.macos.ENOTEMPTY), - () => dir.deleteSync(), - ); + expectFileSystemException(ErrorCodes.ENOTEMPTY, () { + dir.deleteSync(); + }); }); test('succeedsIfNonEmptyDirectoryExistsAndRecursiveTrue', () { @@ -727,13 +730,13 @@ void runCommonTests( }); test('throwsIfDirectoryDoesntExistAndRecursiveFalse', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).deleteSync(); }); }); test('throwsIfDirectoryDoesntExistAndRecursiveTrue', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).deleteSync(recursive: true); }); }); @@ -746,7 +749,7 @@ void runCommonTests( test('throwsIfPathReferencesFileAndRecursiveFalse', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.directory(ns('/foo')).deleteSync(); }); }); @@ -794,14 +797,14 @@ void runCommonTests( test('throwsIfPathReferencesLinkToFileAndRecursiveFalse', () { fs.file(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.directory(ns('/bar')).deleteSync(); }); }); test('throwsIfPathReferencesLinkToNotFoundAndRecursiveFalse', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.ENOTDIR, () { + expectFileSystemException(ErrorCodes.ENOTDIR, () { fs.directory(ns('/foo')).deleteSync(); }); }); @@ -816,26 +819,27 @@ void runCommonTests( fs.link(ns('/foo')).createSync(ns('/bar')); fs.link(ns('/bar')).createSync(ns('/baz')); fs.link(ns('/baz'))..createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.ETIME, () { - fs.directory(ns('/foo')).resolveSymbolicLinksSync(); - }); + expectFileSystemException( + anyOf(ErrorCodes.EMLINK, ErrorCodes.ELOOP), + () => fs.directory(ns('/foo')).resolveSymbolicLinksSync(), + ); }); test('throwsIfPathNotFoundInTraversal', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo/bar')).resolveSymbolicLinksSync(); }); }); test('throwsIfPathNotFoundAtTail', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).resolveSymbolicLinksSync(); }); }); test('throwsIfPathNotFoundInMiddleThenBackedOut', () { fs.directory(ns('/foo/bar')).createSync(recursive: true); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo/baz/../bar')).resolveSymbolicLinksSync(); }); }); @@ -945,7 +949,7 @@ void runCommonTests( }); test('throwsIfDirectoryDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/foo')).createTempSync(); }); }); @@ -975,7 +979,7 @@ void runCommonTests( test('throwsWithNestedPathPrefixThatDoesntExist', () { Directory dir = fs.directory(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { dir.createTempSync('bar/baz'); }); }); @@ -1009,7 +1013,7 @@ void runCommonTests( }); test('throwsIfDirectoryDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.directory(ns('/bar')).listSync(); }); }); @@ -1112,7 +1116,7 @@ void runCommonTests( }); test('throwsIfAncestorDoesntExistRecursiveFalse', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo/bar')).createSync(); }); }); @@ -1124,7 +1128,7 @@ void runCommonTests( test('throwsIfAlreadyExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).createSync(); }); }); @@ -1132,7 +1136,7 @@ void runCommonTests( test('throwsIfAlreadyExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/bar')).createSync(); }); }); @@ -1155,10 +1159,10 @@ void runCommonTests( test('throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal', () { fs.link(ns('/foo')).createSync(ns('/bar/baz')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).createSync(); }); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).createSync(recursive: true); }); }); @@ -1166,7 +1170,7 @@ void runCommonTests( /* test('throwsIfPathSegmentIsLinkToNotFoundAndRecursiveTrue', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo/baz')).createSync(recursive: true); }); }); @@ -1200,7 +1204,7 @@ void runCommonTests( test('throwsIfDestinationDoesntExistViaTraversal', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { f.renameSync(ns('/bar/baz')); }); }); @@ -1216,7 +1220,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsDirectory', () { File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { f.renameSync(ns('/bar')); }); }); @@ -1237,7 +1241,7 @@ void runCommonTests( File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/baz')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { f.renameSync(ns('/baz')); }); }); @@ -1252,14 +1256,14 @@ void runCommonTests( }); test('throwsIfSourceDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).renameSync(ns('/bar')); }); }); @@ -1278,14 +1282,14 @@ void runCommonTests( test('throwsIfSourceExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/bar')).renameSync(ns('/baz')); }); }); test('throwsIfSourceExistsAsLinkToNotFound', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).renameSync(ns('/baz')); }); }); @@ -1310,7 +1314,7 @@ void runCommonTests( test('throwsIfDestinationDoesntExistViaTraversal', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { f.copySync(ns('/bar/baz')); }); }); @@ -1332,7 +1336,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsDirectory', () { File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { f.copySync(ns('/bar')); }); }); @@ -1360,20 +1364,20 @@ void runCommonTests( File f = fs.file(ns('/foo'))..createSync(); fs.directory(ns('/bar')).createSync(); fs.link(ns('/baz')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { f.copySync(ns('/baz')); }); }); test('throwsIfSourceDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).copySync(ns('/bar')); }); }); test('throwsIfSourceExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).copySync(ns('/bar')); }); }); @@ -1444,14 +1448,14 @@ void runCommonTests( group('length', () { test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).lengthSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).lengthSync(); }); }); @@ -1495,14 +1499,14 @@ void runCommonTests( }); test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).lastAccessedSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).lastAccessedSync(); }); }); @@ -1522,14 +1526,14 @@ void runCommonTests( final DateTime time = new DateTime(1999); test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).setLastAccessedSync(time); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).setLastAccessedSync(time); }); }); @@ -1559,14 +1563,14 @@ void runCommonTests( }); test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).lastModifiedSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).lastModifiedSync(); }); }); @@ -1586,14 +1590,14 @@ void runCommonTests( final DateTime time = new DateTime(1999); test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).setLastModifiedSync(time); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).setLastModifiedSync(time); }); }); @@ -1616,7 +1620,7 @@ void runCommonTests( void testIfDoesntExistAtTail(FileMode mode) { if (mode == FileMode.READ) { test('throwsIfDoesntExistAtTail', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/bar')).openSync(mode: mode); }); }); @@ -1631,7 +1635,7 @@ void runCommonTests( void testThrowsIfDoesntExistViaTraversal(FileMode mode) { test('throwsIfDoesntExistViaTraversal', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/bar/baz')).openSync(mode: mode); }); }); @@ -1697,19 +1701,19 @@ void runCommonTests( if (mode == FileMode.WRITE_ONLY || mode == FileMode.WRITE_ONLY_APPEND) { test('throwsIfReadByte', () { - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { raf.readByteSync(); }); }); test('throwsIfRead', () { - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { raf.readSync(2); }); }); test('throwsIfReadInto', () { - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { raf.readIntoSync(new List(5)); }); }); @@ -1767,19 +1771,19 @@ void runCommonTests( if (mode == FileMode.READ) { test('throwsIfWriteByte', () { - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { raf.writeByteSync(0xBAD); }); }); test('throwsIfWriteFrom', () { - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { raf.writeFromSync([1, 2, 3, 4]); }); }); test('throwsIfWriteString', () { - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { raf.writeStringSync('This should throw.'); }); }); @@ -1917,7 +1921,7 @@ void runCommonTests( } test('throwsIfSetToNegativeNumber', () { - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { raf.setPositionSync(-12); }); }); @@ -1925,7 +1929,7 @@ void runCommonTests( if (mode == FileMode.READ) { test('throwsIfTruncate', () { - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { raf.truncateSync(5); }); }); @@ -1953,7 +1957,7 @@ void runCommonTests( }); test('throwsIfSetToNegativeNumber', () { - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { raf.truncateSync(-2); }); }); @@ -1989,8 +1993,7 @@ void runCommonTests( group('openRead', () { test('throwsIfDoesntExist', () { Stream> stream = fs.file(ns('/foo')).openRead(); - expect(stream.drain(), - throwsFileSystemException(ErrorCodes.linux.ENOENT)); + expect(stream.drain(), throwsFileSystemException(ErrorCodes.ENOENT)); }); test('succeedsIfExistsAsFile', () async { @@ -2005,8 +2008,7 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); Stream> stream = fs.file(ns('/foo')).openRead(); - expect(stream.drain(), - throwsFileSystemException(ErrorCodes.linux.EISDIR)); + expect(stream.drain(), throwsFileSystemException(ErrorCodes.EISDIR)); }); test('succeedsIfExistsAsLinkToFile', () async { @@ -2065,14 +2067,14 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); expect(fs.file(ns('/foo')).openWrite().close(), - throwsFileSystemException(ErrorCodes.linux.EISDIR)); + throwsFileSystemException(ErrorCodes.EISDIR)); }); test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); expect(fs.file(ns('/bar')).openWrite().close(), - throwsFileSystemException(ErrorCodes.linux.EISDIR)); + throwsFileSystemException(ErrorCodes.EISDIR)); }); test('throwsIfModeIsRead', () { @@ -2272,14 +2274,14 @@ void runCommonTests( group('readAsBytes', () { test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).readAsBytesSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).readAsBytesSync(); }); }); @@ -2287,7 +2289,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/bar')).readAsBytesSync(); }); }); @@ -2313,14 +2315,14 @@ void runCommonTests( group('readAsString', () { test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).readAsStringSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).readAsStringSync(); }); }); @@ -2328,7 +2330,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/bar')).readAsStringSync(); }); }); @@ -2361,14 +2363,14 @@ void runCommonTests( group('readAsLines', () { test('throwsIfDoesntExist', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).readAsLinesSync(); }); }); test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).readAsLinesSync(); }); }); @@ -2376,7 +2378,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/bar')).readAsLinesSync(); }); }); @@ -2422,7 +2424,7 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).writeAsBytesSync([1, 2, 3, 4]); }); }); @@ -2430,7 +2432,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).writeAsBytesSync([1, 2, 3, 4]); }); }); @@ -2444,7 +2446,7 @@ void runCommonTests( test('throwsIfFileModeRead', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { f.writeAsBytesSync([1], mode: FileMode.READ); }); }); @@ -2486,7 +2488,7 @@ void runCommonTests( test('throwsIfExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).writeAsStringSync('Hello world'); }); }); @@ -2494,7 +2496,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectory', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).writeAsStringSync('Hello world'); }); }); @@ -2508,7 +2510,7 @@ void runCommonTests( test('throwsIfFileModeRead', () { File f = fs.file(ns('/foo'))..createSync(); - expectFileSystemException(ErrorCodes.linux.EBADF, () { + expectFileSystemException(ErrorCodes.EBADF, () { f.writeAsStringSync('Hello world', mode: FileMode.READ); }); }); @@ -2624,13 +2626,13 @@ void runCommonTests( }); test('throwsIfDoesntExistAndRecursiveFalse', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).deleteSync(); }); }); test('throwsIfDoesntExistAndRecursiveTrue', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.file(ns('/foo')).deleteSync(recursive: true); }); }); @@ -2643,7 +2645,7 @@ void runCommonTests( test('throwsIfExistsAsDirectoryAndRecursiveFalse', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/foo')).deleteSync(); }); }); @@ -2676,7 +2678,7 @@ void runCommonTests( test('throwsIfExistsAsLinkToDirectoryAndRecursiveFalse', () { fs.directory(ns('/foo')).createSync(); fs.link(ns('/bar')).createSync(ns('/foo')); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.file(ns('/bar')).deleteSync(); }); }); @@ -2807,20 +2809,20 @@ void runCommonTests( }); test('throwsIfLinkDoesntExistAtTail', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo')).deleteSync(); }); }); test('throwsIfLinkDoesntExistViaTraversal', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo/bar')).deleteSync(); }); }); test('throwsIfPathReferencesFileAndRecursiveFalse', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { fs.link(ns('/foo')).deleteSync(); }); }); @@ -2834,9 +2836,12 @@ void runCommonTests( test('throwsIfPathReferencesDirectoryAndRecursiveFalse', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { - fs.link(ns('/foo')).deleteSync(); - }); + // TODO(tvolkert): Change this to just be 'Is a directory' + // once Dart 1.22 is stable. + expectFileSystemException( + anyOf(ErrorCodes.EINVAL, ErrorCodes.EISDIR), + () => fs.link(ns('/foo')).deleteSync(), + ); }); test('succeedsIfPathReferencesDirectoryAndRecursiveTrue', () { @@ -2926,7 +2931,7 @@ void runCommonTests( }); test('throwsIfLinkDoesntExistViaTraversalAndRecursiveFalse', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo/bar')).createSync('baz'); }); }); @@ -2942,28 +2947,28 @@ void runCommonTests( test('throwsIfAlreadyExistsAsFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EEXIST, () { + expectFileSystemException(ErrorCodes.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/bar')); }); }); test('throwsIfAlreadyExistsAsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EEXIST, () { + expectFileSystemException(ErrorCodes.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/bar')); }); }); test('throwsIfAlreadyExistsWithSameTarget', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.EEXIST, () { + expectFileSystemException(ErrorCodes.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/bar')); }); }); test('throwsIfAlreadyExistsWithDifferentTarget', () { fs.link(ns('/foo')).createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.EEXIST, () { + expectFileSystemException(ErrorCodes.EEXIST, () { fs.link(ns('/foo')).createSync(ns('/baz')); }); }); @@ -2976,29 +2981,32 @@ void runCommonTests( }); test('throwsIfLinkDoesntExistAtTail', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo')).updateSync(ns('/bar')); }); }); test('throwsIfLinkDoesntExistViaTraversal', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo/bar')).updateSync(ns('/baz')); }); }); test('throwsIfPathReferencesFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { fs.link(ns('/foo')).updateSync(ns('/bar')); }); }); test('throwsIfPathReferencesDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { - fs.link(ns('/foo')).updateSync(ns('/bar')); - }); + // TODO(tvolkert): Change this to just be 'Is a directory' + // once Dart 1.22 is stable. + expectFileSystemException( + anyOf(ErrorCodes.EINVAL, ErrorCodes.EISDIR), + () => fs.link(ns('/foo')).updateSync(ns('/bar')), + ); }); test('succeedsIfNewTargetSameAsOldTarget', () { @@ -3034,27 +3042,27 @@ void runCommonTests( group('target', () { test('throwsIfLinkDoesntExistAtTail', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo')).targetSync(); }); }); test('throwsIfLinkDoesntExistViaTraversal', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo/bar')).targetSync(); }); }); test('throwsIfPathReferencesFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo')).targetSync(); }); }); test('throwsIfPathReferencesDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo')).targetSync(); }); }); @@ -3091,27 +3099,27 @@ void runCommonTests( }); test('throwsIfSourceDoesntExistAtTail', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceDoesntExistViaTraversal', () { - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { fs.link(ns('/foo/bar')).renameSync(ns('/bar')); }); }); test('throwsIfSourceIsFile', () { fs.file(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { fs.link(ns('/foo')).renameSync(ns('/bar')); }); }); test('throwsIfSourceIsDirectory', () { fs.directory(ns('/foo')).createSync(); - expectFileSystemException(ErrorCodes.linux.EISDIR, () { + expectFileSystemException(ErrorCodes.EISDIR, () { fs.link(ns('/foo')).renameSync(ns('/bar')); }); }); @@ -3174,7 +3182,7 @@ void runCommonTests( test('throwsIfDestinationDoesntExistViaTraversal', () { Link l = fs.link(ns('/foo'))..createSync(ns('/bar')); - expectFileSystemException(ErrorCodes.linux.ENOENT, () { + expectFileSystemException(ErrorCodes.ENOENT, () { l.renameSync(ns('/baz/qux')); }); }); @@ -3182,7 +3190,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsFile', () { Link l = fs.link(ns('/foo'))..createSync(ns('/bar')); fs.file(ns('/baz')).createSync(); - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { l.renameSync(ns('/baz')); }); }); @@ -3190,7 +3198,7 @@ void runCommonTests( test('throwsIfDestinationExistsAsDirectory', () { Link l = fs.link(ns('/foo'))..createSync(ns('/bar')); fs.directory(ns('/baz')).createSync(); - expectFileSystemException(ErrorCodes.linux.EINVAL, () { + expectFileSystemException(ErrorCodes.EINVAL, () { l.renameSync(ns('/baz')); }); }); From 111f8d1e4ae51fb0a5a9745e83cfd5285c1121e5 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Wed, 22 Feb 2017 11:09:50 -0800 Subject: [PATCH 3/5] Actually switch on operating system --- lib/src/interface.dart | 22 ++++++------------- lib/src/interface/directory.dart | 5 ++++- lib/src/interface/error_codes.dart | 7 +++--- lib/src/interface/file.dart | 6 ++++- lib/src/interface/file_system.dart | 10 ++++++++- lib/src/interface/file_system_entity.dart | 6 ++++- lib/src/interface/link.dart | 5 ++++- lib/src/interface/platform_shim.dart | 6 +++++ lib/src/interface/platform_shim_dart_io.dart | 10 +++++++++ lib/src/interface/platform_shim_internal.dart | 8 +++++++ 10 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 lib/src/interface/platform_shim.dart create mode 100644 lib/src/interface/platform_shim_dart_io.dart create mode 100644 lib/src/interface/platform_shim_internal.dart diff --git a/lib/src/interface.dart b/lib/src/interface.dart index abdde1f..4662e35 100644 --- a/lib/src/interface.dart +++ b/lib/src/interface.dart @@ -4,18 +4,10 @@ library file.src.interface; -import 'dart:async'; -import 'dart:convert'; - -import 'package:path/path.dart' as path; - -import 'io.dart' as io; - -export 'io.dart'; - -part 'interface/directory.dart'; -part 'interface/error_codes.dart'; -part 'interface/file.dart'; -part 'interface/file_system.dart'; -part 'interface/file_system_entity.dart'; -part 'interface/link.dart'; +export 'interface/directory.dart'; +export 'interface/error_codes.dart'; +export 'interface/file.dart'; +export 'interface/file_system.dart'; +export 'interface/file_system_entity.dart'; +export 'interface/link.dart'; +export 'io.dart' hide Directory, File, FileSystemEntity, Link; diff --git a/lib/src/interface/directory.dart b/lib/src/interface/directory.dart index 10740ca..f19c67f 100644 --- a/lib/src/interface/directory.dart +++ b/lib/src/interface/directory.dart @@ -2,7 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of file.src.interface; +import 'dart:async'; + +import 'file_system_entity.dart'; +import '../io.dart' as io; /// A reference to a directory on the file system. abstract class Directory implements FileSystemEntity, io.Directory { diff --git a/lib/src/interface/error_codes.dart b/lib/src/interface/error_codes.dart index 357cedd..6273278 100644 --- a/lib/src/interface/error_codes.dart +++ b/lib/src/interface/error_codes.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of file.src.interface; +import 'platform_shim.dart'; /// Operating system error codes. class ErrorCodes { @@ -86,7 +86,8 @@ class ErrorCodes { /// File name too long // ignore: non_constant_identifier_names - static int get ENAMETOOLONG => _platform((_Codes codes) => codes.enametoolong); + static int get ENAMETOOLONG => + _platform((_Codes codes) => codes.enametoolong); /// File table overflow // ignore: non_constant_identifier_names @@ -165,7 +166,7 @@ class ErrorCodes { static int get EXDEV => _platform((_Codes codes) => codes.exdev); static int _platform(int getCode(_Codes codes)) { - _Codes codes = _platforms['macos']; // TODO(tvolkert): switch on platform + _Codes codes = _platforms[operatingSystem]; return getCode(codes); } } diff --git a/lib/src/interface/file.dart b/lib/src/interface/file.dart index 5523a78..ce200d5 100644 --- a/lib/src/interface/file.dart +++ b/lib/src/interface/file.dart @@ -2,7 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of file.src.interface; +import 'dart:async'; +import 'dart:convert'; + +import 'file_system_entity.dart'; +import '../io.dart' as io; /// A reference to a file on the file system. abstract class File implements FileSystemEntity, io.File { diff --git a/lib/src/interface/file_system.dart b/lib/src/interface/file_system.dart index abd954e..084ba82 100644 --- a/lib/src/interface/file_system.dart +++ b/lib/src/interface/file_system.dart @@ -2,7 +2,15 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of file.src.interface; +import 'dart:async'; + +import 'package:path/path.dart' as path; + +import 'directory.dart'; +import 'file.dart'; +import 'file_system_entity.dart'; +import 'link.dart'; +import '../io.dart' as io; /// A generic representation of a file system. /// diff --git a/lib/src/interface/file_system_entity.dart b/lib/src/interface/file_system_entity.dart index a6152d5..53faa45 100644 --- a/lib/src/interface/file_system_entity.dart +++ b/lib/src/interface/file_system_entity.dart @@ -2,7 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of file.src.interface; +import 'dart:async'; + +import 'directory.dart'; +import 'file_system.dart'; +import '../io.dart' as io; /// The common super class for [File], [Directory], and [Link] objects. abstract class FileSystemEntity implements io.FileSystemEntity { diff --git a/lib/src/interface/link.dart b/lib/src/interface/link.dart index 261b237..1288363 100644 --- a/lib/src/interface/link.dart +++ b/lib/src/interface/link.dart @@ -2,7 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of file.src.interface; +import 'dart:async'; + +import 'file_system_entity.dart'; +import '../io.dart' as io; /// A reference to a symbolic link on the file system. abstract class Link implements FileSystemEntity, io.Link { diff --git a/lib/src/interface/platform_shim.dart b/lib/src/interface/platform_shim.dart new file mode 100644 index 0000000..6362bbc --- /dev/null +++ b/lib/src/interface/platform_shim.dart @@ -0,0 +1,6 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +export 'platform_shim_internal.dart' + if (dart.library.io) 'platform_shim_dart_io.dart'; diff --git a/lib/src/interface/platform_shim_dart_io.dart b/lib/src/interface/platform_shim_dart_io.dart new file mode 100644 index 0000000..ad383a1 --- /dev/null +++ b/lib/src/interface/platform_shim_dart_io.dart @@ -0,0 +1,10 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:io'; + +/// If we have `dart:io` available, we pull the current operating system from +/// the [Platform] class, so we'll get errno values that match our current +/// operating system. +final String operatingSystem = Platform.operatingSystem; diff --git a/lib/src/interface/platform_shim_internal.dart b/lib/src/interface/platform_shim_internal.dart new file mode 100644 index 0000000..957cc76 --- /dev/null +++ b/lib/src/interface/platform_shim_internal.dart @@ -0,0 +1,8 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// In environments that don't have `dart:io`, we can't access the Platform +/// class to determine what platform we're on, so we just pretend we're on +/// Linux, meaning we'll get errno values that match Linux errno.h. +const String operatingSystem = 'linux'; From 242d2d5e65de2d7687597c7759b3765dc5dc6c7b Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Wed, 22 Feb 2017 12:08:09 -0800 Subject: [PATCH 4/5] Refactor code --- lib/src/backends/chroot/chroot_directory.dart | 40 ++++----------- lib/src/backends/chroot/chroot_file.dart | 32 +++--------- .../backends/chroot/chroot_file_system.dart | 26 +++------- .../chroot/chroot_file_system_entity.dart | 26 +++------- lib/src/backends/memory/memory_directory.dart | 8 +-- lib/src/backends/memory/memory_file.dart | 22 ++------- .../memory/memory_file_system_entity.dart | 4 +- lib/src/backends/memory/memory_link.dart | 22 ++------- lib/src/backends/memory/utils.dart | 27 +++------- lib/src/common.dart | 49 ++++++++++++++++++- lib/src/interface/error_codes.dart | 3 +- ..._dart_io.dart => error_codes_dart_io.dart} | 2 +- ...nternal.dart => error_codes_internal.dart} | 2 +- lib/src/interface/platform_shim.dart | 6 --- test/common_tests.dart | 26 +++++++--- 15 files changed, 121 insertions(+), 174 deletions(-) rename lib/src/interface/{platform_shim_dart_io.dart => error_codes_dart_io.dart} (93%) rename lib/src/interface/{platform_shim_internal.dart => error_codes_internal.dart} (85%) delete mode 100644 lib/src/interface/platform_shim.dart diff --git a/lib/src/backends/chroot/chroot_directory.dart b/lib/src/backends/chroot/chroot_directory.dart index 246c18c..102a1c1 100644 --- a/lib/src/backends/chroot/chroot_directory.dart +++ b/lib/src/backends/chroot/chroot_directory.dart @@ -30,24 +30,18 @@ class _ChrootDirectory extends _ChrootFileSystemEntity Future rename(String newPath) async { if (_isLink) { if (await fileSystem.type(path) != expectedType) { - String msg = 'Not a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOTDIR)); + throw common.notADirectory(path); } FileSystemEntityType type = await fileSystem.type(newPath); if (type != FileSystemEntityType.NOT_FOUND) { if (type != expectedType) { - String msg = 'Not a directory'; - throw new FileSystemException( - msg, newPath, new OSError(msg, ErrorCodes.ENOTDIR)); + throw common.notADirectory(newPath); } if (!(await fileSystem .directory(newPath) .list(followLinks: false) .isEmpty)) { - String msg = 'Directory not empty'; - throw new FileSystemException( - msg, newPath, new OSError(msg, ErrorCodes.ENOTEMPTY)); + throw common.directoryNotEmpty(newPath); } } String target = await fileSystem.link(path).target(); @@ -64,24 +58,18 @@ class _ChrootDirectory extends _ChrootFileSystemEntity Directory renameSync(String newPath) { if (_isLink) { if (fileSystem.typeSync(path) != expectedType) { - String msg = 'Not a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOTDIR)); + throw common.notADirectory(path); } FileSystemEntityType type = fileSystem.typeSync(newPath); if (type != FileSystemEntityType.NOT_FOUND) { if (type != expectedType) { - String msg = 'Not a directory'; - throw new FileSystemException( - msg, newPath, new OSError(msg, ErrorCodes.ENOTDIR)); + throw common.notADirectory(newPath); } if (fileSystem .directory(newPath) .listSync(followLinks: false) .isNotEmpty) { - String msg = 'Directory not empty'; - throw new FileSystemException( - msg, newPath, new OSError(msg, ErrorCodes.ENOTEMPTY)); + throw common.directoryNotEmpty(newPath); } } String target = fileSystem.link(path).targetSync(); @@ -111,13 +99,9 @@ class _ChrootDirectory extends _ChrootFileSystemEntity if (_isLink) { switch (await fileSystem.type(path)) { case FileSystemEntityType.NOT_FOUND: - String msg = 'No such file or directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOENT)); + throw common.noSuchFileOrDirectory(path); case FileSystemEntityType.FILE: - String msg = 'File exists'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.EEXIST)); + throw common.fileExists(path); case FileSystemEntityType.DIRECTORY: // Nothing to do. return this; @@ -134,13 +118,9 @@ class _ChrootDirectory extends _ChrootFileSystemEntity if (_isLink) { switch (fileSystem.typeSync(path)) { case FileSystemEntityType.NOT_FOUND: - String msg = 'No such file or directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOENT)); + throw common.noSuchFileOrDirectory(path); case FileSystemEntityType.FILE: - String msg = 'File exists'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.EEXIST)); + throw common.fileExists(path); case FileSystemEntityType.DIRECTORY: // Nothing to do. return; diff --git a/lib/src/backends/chroot/chroot_file.dart b/lib/src/backends/chroot/chroot_file.dart index 8d72b47..3e12c43 100644 --- a/lib/src/backends/chroot/chroot_file.dart +++ b/lib/src/backends/chroot/chroot_file.dart @@ -45,9 +45,7 @@ class _ChrootFile extends _ChrootFileSystemEntity }; break; case FileSystemEntityType.DIRECTORY: - String msg = 'Is a directory'; - throw new FileSystemException( - msg, newPath, new OSError(msg, ErrorCodes.EISDIR)); + throw common.isADirectory(newPath); default: // Should never happen. throw new AssertionError(); @@ -57,13 +55,9 @@ class _ChrootFile extends _ChrootFileSystemEntity if (_isLink) { switch (await fileSystem.type(path)) { case FileSystemEntityType.NOT_FOUND: - String msg = 'No such file or directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOENT)); + throw common.noSuchFileOrDirectory(path); case FileSystemEntityType.DIRECTORY: - String msg = 'Is a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.EISDIR)); + throw common.isADirectory(path); case FileSystemEntityType.FILE: await setUp(); await fileSystem.delegate @@ -100,9 +94,7 @@ class _ChrootFile extends _ChrootFileSystemEntity }; break; case FileSystemEntityType.DIRECTORY: - String msg = 'Is a directory'; - throw new FileSystemException( - msg, newPath, new OSError(msg, ErrorCodes.EISDIR)); + throw common.isADirectory(newPath); default: // Should never happen. throw new AssertionError(); @@ -112,13 +104,9 @@ class _ChrootFile extends _ChrootFileSystemEntity if (_isLink) { switch (fileSystem.typeSync(path)) { case FileSystemEntityType.NOT_FOUND: - String msg = 'No such file or directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOENT)); + throw common.noSuchFileOrDirectory(path); case FileSystemEntityType.DIRECTORY: - String msg = 'Is a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.EISDIR)); + throw common.isADirectory(path); case FileSystemEntityType.FILE: setUp(); fileSystem.delegate @@ -161,9 +149,7 @@ class _ChrootFile extends _ChrootFileSystemEntity // Nothing to do. return this; case FileSystemEntityType.DIRECTORY: - String msg = 'Is a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.EISDIR)); + throw common.isADirectory(path); default: throw new AssertionError(); } @@ -195,9 +181,7 @@ class _ChrootFile extends _ChrootFileSystemEntity // Nothing to do. return; case FileSystemEntityType.DIRECTORY: - String msg = 'Is a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.EISDIR)); + throw common.isADirectory(path); default: throw new AssertionError(); } diff --git a/lib/src/backends/chroot/chroot_file_system.dart b/lib/src/backends/chroot/chroot_file_system.dart index 1ff45e8..ae5135d 100644 --- a/lib/src/backends/chroot/chroot_file_system.dart +++ b/lib/src/backends/chroot/chroot_file_system.dart @@ -114,13 +114,9 @@ class ChrootFileSystem extends FileSystem { case FileSystemEntityType.DIRECTORY: break; case FileSystemEntityType.NOT_FOUND: - String msg = 'No such file or directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOENT)); + throw common.noSuchFileOrDirectory(path); default: - String msg = 'Not a directory'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOTDIR)); + throw common.notADirectory(path); } assert(() { p.Context ctx = delegate.path; @@ -303,9 +299,7 @@ class ChrootFileSystem extends FileSystem { case FileSystemEntityType.FILE: breadcrumbs.clear(); if (parts.isNotEmpty) { - String msg = 'Not a directory'; - throw new FileSystemException( - msg, currentPath, new OSError(msg, ErrorCodes.ENOTDIR)); + throw common.notADirectory(currentPath); } break; case FileSystemEntityType.NOT_FOUND: @@ -314,12 +308,6 @@ class ChrootFileSystem extends FileSystem { return getCurrentPath(); } - FileSystemException notFoundException() { - String msg = 'No such file or directory'; - return new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ENOENT)); - } - switch (notFound) { case _NotFoundBehavior.mkdir: if (parts.isNotEmpty) { @@ -332,9 +320,9 @@ 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: @@ -342,9 +330,7 @@ class ChrootFileSystem extends FileSystem { break; } if (!breadcrumbs.add(currentPath)) { - String msg = 'Too many levels of symbolic links'; - throw new FileSystemException( - msg, path, new OSError(msg, ErrorCodes.ELOOP)); + throw common.tooManyLevelsOfSymbolicLinks(path); } String target = delegate.link(realPath).targetSync(); if (ctx.isAbsolute(target)) { diff --git a/lib/src/backends/chroot/chroot_file_system_entity.dart b/lib/src/backends/chroot/chroot_file_system_entity.dart index 7ec04f7..ed777de 100644 --- a/lib/src/backends/chroot/chroot_file_system_entity.dart +++ b/lib/src/backends/chroot/chroot_file_system_entity.dart @@ -116,16 +116,9 @@ abstract class _ChrootFileSystemEntity fs.currentDirectory = ns('/foo'), + () { + fs.currentDirectory = ns('/foo'); + }, ); }); }); @@ -538,7 +540,9 @@ void runCommonTests( // once Dart 1.22 is stable. expectFileSystemException( anyOf(ErrorCodes.EEXIST, ErrorCodes.ENOTDIR), - () => fs.directory(ns('/bar')).createSync(), + () { + fs.directory(ns('/bar')).createSync(); + }, ); }); @@ -624,9 +628,13 @@ void runCommonTests( test('throwsIfDestinationIsNonEmptyDirectory', () { fs.file(ns('/bar/baz')).createSync(recursive: true); Directory src = fs.directory(ns('/foo'))..createSync(); + // The error will be 'Directory not empty' on OS X, but it will be + // 'File exists' on Linux. expectFileSystemException( anyOf(ErrorCodes.ENOTEMPTY, ErrorCodes.EEXIST), - () => src.renameSync(ns('/bar')), + () { + src.renameSync(ns('/bar')); + }, ); }); @@ -821,7 +829,9 @@ void runCommonTests( fs.link(ns('/baz'))..createSync(ns('/foo')); expectFileSystemException( anyOf(ErrorCodes.EMLINK, ErrorCodes.ELOOP), - () => fs.directory(ns('/foo')).resolveSymbolicLinksSync(), + () { + fs.directory(ns('/foo')).resolveSymbolicLinksSync(); + }, ); }); @@ -2840,7 +2850,9 @@ void runCommonTests( // once Dart 1.22 is stable. expectFileSystemException( anyOf(ErrorCodes.EINVAL, ErrorCodes.EISDIR), - () => fs.link(ns('/foo')).deleteSync(), + () { + fs.link(ns('/foo')).deleteSync(); + }, ); }); @@ -3005,7 +3017,9 @@ void runCommonTests( // once Dart 1.22 is stable. expectFileSystemException( anyOf(ErrorCodes.EINVAL, ErrorCodes.EISDIR), - () => fs.link(ns('/foo')).updateSync(ns('/bar')), + () { + fs.link(ns('/foo')).updateSync(ns('/bar')); + }, ); }); From 799d38d270c802014f7a812ebaa505e469052bdf Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Wed, 22 Feb 2017 13:19:40 -0800 Subject: [PATCH 5/5] Update version, add TODO --- CHANGELOG.md | 4 ++++ lib/src/interface/error_codes.dart | 1 + pubspec.yaml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dce9e49..4162b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/interface/error_codes.dart b/lib/src/interface/error_codes.dart index 656a0cc..48fc5db 100644 --- a/lib/src/interface/error_codes.dart +++ b/lib/src/interface/error_codes.dart @@ -6,6 +6,7 @@ import 'error_codes_internal.dart' if (dart.library.io) 'error_codes_dart_io.dart'; /// Operating system error codes. +// TODO(tvolkert): Remove (https://github.com/dart-lang/sdk/issues/28860) class ErrorCodes { ErrorCodes._(); diff --git a/pubspec.yaml b/pubspec.yaml index 5026759..3001c16 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: file -version: 2.1.0 +version: 2.2.0 authors: - Matan Lurey - Yegor Jbanov