Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit d9dad57

Browse files
authored
Windows fixes (#42)
1 parent 4aaaddf commit d9dad57

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

lib/src/backends/chroot/chroot_directory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
158158
}
159159

160160
FileSystemEntity _denormalize(io.FileSystemEntity entity, String dirname) {
161-
p.Context ctx = fileSystem._context;
161+
p.Context ctx = fileSystem.path;
162162
String relativePart = ctx.relative(entity.path, from: dirname);
163163
String entityPath = ctx.join(path, relativePart);
164164
if (entity is io.File) {

lib/src/backends/chroot/chroot_file_system.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class ChrootFileSystem extends FileSystem {
5050
///
5151
/// **NOTE**: [root] must be a _canonicalized_ path; see [p.canonicalize].
5252
ChrootFileSystem(this.delegate, this.root) {
53-
if (root != p.canonicalize(root)) {
53+
if (root != delegate.path.canonicalize(root)) {
5454
throw new ArgumentError.value(root, 'root', 'Must be canonical path');
5555
}
5656
_cwd = _localRoot;
5757
}
5858

5959
/// Gets the root path, as seen by entities in this file system.
60-
String get _localRoot => p.rootPrefix(root);
60+
String get _localRoot => delegate.path.rootPrefix(root);
6161

6262
@override
6363
Directory directory(dynamic path) =>
@@ -82,8 +82,6 @@ class ChrootFileSystem extends FileSystem {
8282
return directory(_systemTemp)..createSync();
8383
}
8484

85-
p.Context get _context => new p.Context(current: _cwd);
86-
8785
/// Creates a directory object pointing to the current working directory.
8886
///
8987
/// **NOTE** This does _not_ proxy to the underlying file system's current
@@ -120,7 +118,10 @@ class ChrootFileSystem extends FileSystem {
120118
default:
121119
throw new FileSystemException('Not a directory');
122120
}
123-
assert(() => p.isAbsolute(value) && value == p.canonicalize(value));
121+
assert(() {
122+
p.Context ctx = delegate.path;
123+
return ctx.isAbsolute(value) && value == ctx.canonicalize(value);
124+
});
124125
_cwd = value;
125126
}
126127

@@ -195,7 +196,7 @@ class ChrootFileSystem extends FileSystem {
195196
bool relative: false,
196197
bool keepInJail: false,
197198
}) {
198-
assert(_context.isAbsolute(realPath));
199+
assert(path.isAbsolute(realPath));
199200
if (!realPath.startsWith(root)) {
200201
if (keepInJail) {
201202
return _localRoot;
@@ -209,7 +210,7 @@ class ChrootFileSystem extends FileSystem {
209210
}
210211
if (relative) {
211212
assert(result.startsWith(_cwd));
212-
result = _context.relative(result, from: _cwd);
213+
result = path.relative(result, from: _cwd);
213214
}
214215
return result;
215216
}
@@ -231,7 +232,7 @@ class ChrootFileSystem extends FileSystem {
231232
if (resolve) {
232233
localPath = _resolve(localPath, followLinks: followLinks);
233234
} else {
234-
assert(() => _context.isAbsolute(localPath));
235+
assert(() => path.isAbsolute(localPath));
235236
}
236237
return '$root$localPath';
237238
}
@@ -261,7 +262,7 @@ class ChrootFileSystem extends FileSystem {
261262
bool followLinks: true,
262263
_NotFoundBehavior notFound: _NotFoundBehavior.allow,
263264
}) {
264-
p.Context ctx = _context;
265+
p.Context ctx = this.path;
265266
String root = _localRoot;
266267
List<String> parts, ledger;
267268
if (ctx.isAbsolute(path)) {

lib/src/backends/chroot/chroot_file_system_entity.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
4343

4444
/// Gets the path of this entity as an absolute path (unchanged if the
4545
/// entity already specifies an absolute path).
46-
String get _absolutePath => fileSystem._context.absolute(path);
46+
String get _absolutePath => fileSystem.path.absolute(path);
4747

4848
/// Tells whether this entity's path references a symbolic link.
4949
bool get _isLink =>
@@ -166,5 +166,5 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
166166
throw new UnsupportedError('watch is not supported on ChrootFileSystem');
167167

168168
@override
169-
bool get isAbsolute => fileSystem._context.isAbsolute(path);
169+
bool get isAbsolute => fileSystem.path.isAbsolute(path);
170170
}

test/common_tests.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:io' as io;
99

1010
import 'package:file/file.dart';
1111
import 'package:file/testing.dart';
12+
import 'package:path/path.dart' as p;
1213
import 'package:test/test.dart';
1314
import 'package:test/test.dart' as testpkg show group, setUp, tearDown, test;
1415

@@ -126,17 +127,25 @@ void runCommonTests(
126127
/// Returns [path] prefixed by the [root] namespace.
127128
/// This is only intended for absolute paths.
128129
String ns(String path) {
129-
// We purposefully don't use package:path here because some of our tests
130-
// use non-standard paths that package:path would correct for us
131-
// inadvertently (thus thwarting the purpose of that test).
132-
assert(path.startsWith('/'));
133-
return root == '/' ? path : (path == '/' ? root : '$root$path');
130+
p.Context posix = new p.Context(style: p.Style.posix);
131+
List<String> parts = posix.split(path);
132+
path = fs.path.joinAll(parts);
133+
String rootPrefix = fs.path.rootPrefix(path);
134+
assert(rootPrefix.isNotEmpty);
135+
String result = root == rootPrefix
136+
? path
137+
: (path == rootPrefix
138+
? root
139+
: fs.path.join(root, fs.path.joinAll(parts.sublist(1))));
140+
return result;
134141
}
135142

136143
setUp(() async {
137144
root = rootfn != null ? rootfn() : '/';
138-
assert(root.startsWith('/') && (root == '/' || !root.endsWith('/')));
139145
fs = await createFs();
146+
assert(fs.path.isAbsolute(root));
147+
assert(!root.endsWith(fs.path.separator) ||
148+
fs.path.rootPrefix(root) == root);
140149
});
141150

142151
group('FileSystem', () {
@@ -454,8 +463,8 @@ void runCommonTests(
454463

455464
group('Directory', () {
456465
test('uri', () {
457-
expect(
458-
fs.directory(ns('/foo')).uri.toString(), 'file://${ns('/foo/')}');
466+
expect(fs.directory(ns('/foo')).uri.toString(),
467+
'file://${ns('/foo')}${fs.path.separator}');
459468
expect(fs.directory('foo').uri.toString(), 'foo/');
460469
});
461470

0 commit comments

Comments
 (0)