Try to gracefully handle the cwd being deleted.
diff --git a/.gitignore b/.gitignore
index 813a31e..8608a82 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,8 @@
.buildlog
.pub/
.dart_tool/
+.idea/
build/
-packages
.packages
# Or the files created by dart2js.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 19853b9..129e440 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.6.3
+
+* Don't throw a FileSystemException from `current` if the working directory has
+ been deleted but we have a cached one we can use.
+
## 1.6.2
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
diff --git a/lib/path.dart b/lib/path.dart
index ed70f9d..9b7f1ab 100644
--- a/lib/path.dart
+++ b/lib/path.dart
@@ -81,7 +81,17 @@
///
/// In the browser, this means the current URL, without the last file segment.
String get current {
- var uri = Uri.base;
+ // If the current working directory gets deleted out from under the program,
+ // accessing it will throw an IO exception. In order to avoid transient
+ // errors, if we already have a cached working directory, catch the error and
+ // use that.
+ Uri uri;
+ try {
+ uri = Uri.base;
+ } on Exception {
+ if (_current != null) return _current;
+ rethrow;
+ }
// Converting the base URI to a file path is pretty slow, and the base URI
// rarely changes in practice, so we cache the result here.
diff --git a/pubspec.yaml b/pubspec.yaml
index 5c22cb4..504474b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,10 +1,10 @@
name: path
-version: 1.6.2
+version: 1.6.3-dev
description: >
A string-based path manipulation library. All of the path operations you know
- and love, with solid support on both Windows and POSIX (Linux and Mac OS X)
- machines.
+ and love, with solid support for Windows, POSIX (Linux and Mac OS X), and the
+ web.
author: Dart Team <misc@dartlang.org>
homepage: http://github.com/dart-lang/path
diff --git a/test/io_test.dart b/test/io_test.dart
index 82d8b09..7b9d49d 100644
--- a/test/io_test.dart
+++ b/test/io_test.dart
@@ -35,8 +35,30 @@
}
});
- test('current', () {
- expect(path.current, io.Directory.current.path);
+ group('current', () {
+ test('returns the current working directory', () {
+ expect(path.current, io.Directory.current.path);
+ });
+
+ test('uses the previous working directory if deleted', () {
+ var dir = io.Directory.current.path;
+ try {
+ var tempPath = path.normalize(path.absolute("temp_cwd"));
+ var temp = io.Directory(tempPath);
+ temp.createSync();
+ io.Directory.current = temp;
+
+ // Call "current" once so that it can be cached.
+ expect(path.normalize(path.absolute(path.current)), equals(tempPath));
+
+ temp.deleteSync();
+
+ // Even though the directory no longer exists, no exception is thrown.
+ expect(path.normalize(path.absolute(path.current)), equals(tempPath));
+ } finally {
+ io.Directory.current = dir;
+ }
+ });
});
test('registers changes to the working directory', () {