file.dart
file.dart copied to clipboard
Differences in behaviour between real windows FS and Window-style in-memory FS
I was moving some tests in Flutter over to the memory file system and hit some issues because of differences in behaviour. In the real implementation, if you use a forward slash in a path, it still resolves correctly. However in the memory file system it treats it as a different path.
The below (when run on Windows) prints:
true
false
import 'package:file/local.dart';
import 'package:file/memory.dart';
final localFs = new LocalFileSystem();
final memoryFs = new MemoryFileSystem(style: FileSystemStyle.windows);
main() {
[
new LocalFileSystem(),
new MemoryFileSystem(style: FileSystemStyle.windows),
].forEach((fs) {
// Create a file at test\test.txt
fs.currentDirectory = fs.systemTempDirectory;
fs.directory('test').createSync(recursive: true);
fs.file('test\\test.txt').createSync();
// Check if it exists using a forward slash
print(fs.file('test/test.txt').existsSync());
});
}
I'll fix this in flutter by using the correct slashes, but I guess the intention is for these to behave the same where possible. It's possibly that https://github.com/google/file.dart/issues/56 would cover this, I'm not sure.