Commit 11ca0f1a authored by John McCutchan's avatar John McCutchan Committed by GitHub

Support caching host filesystem symlink targets to speedup DevFS updates (#6798)

parent bbf98d9c
...@@ -35,6 +35,7 @@ import 'src/commands/test.dart'; ...@@ -35,6 +35,7 @@ import 'src/commands/test.dart';
import 'src/commands/trace.dart'; import 'src/commands/trace.dart';
import 'src/commands/update_packages.dart'; import 'src/commands/update_packages.dart';
import 'src/commands/upgrade.dart'; import 'src/commands/upgrade.dart';
import 'src/devfs.dart';
import 'src/device.dart'; import 'src/device.dart';
import 'src/doctor.dart'; import 'src/doctor.dart';
import 'src/globals.dart'; import 'src/globals.dart';
...@@ -83,6 +84,7 @@ Future<Null> main(List<String> args) async { ...@@ -83,6 +84,7 @@ Future<Null> main(List<String> args) async {
// Initialize globals. // Initialize globals.
context[Logger] = new StdoutLogger(); context[Logger] = new StdoutLogger();
context[DeviceManager] = new DeviceManager(); context[DeviceManager] = new DeviceManager();
context[DevFSConfig] = new DevFSConfig();
Doctor.initGlobal(); Doctor.initGlobal();
dynamic result = await runner.run(args); dynamic result = await runner.run(args);
......
...@@ -8,6 +8,7 @@ import 'dart:io'; ...@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'base/context.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'dart/package_map.dart'; import 'dart/package_map.dart';
import 'asset.dart'; import 'asset.dart';
...@@ -16,6 +17,13 @@ import 'vmservice.dart'; ...@@ -16,6 +17,13 @@ import 'vmservice.dart';
typedef void DevFSProgressReporter(int progress, int max); typedef void DevFSProgressReporter(int progress, int max);
class DevFSConfig {
/// Should DevFS assume that symlink targets are stable?
bool cacheSymlinks = false;
}
DevFSConfig get devFSConfig => context[DevFSConfig];
// A file that has been added to a DevFS. // A file that has been added to a DevFS.
class DevFSEntry { class DevFSEntry {
DevFSEntry(this.devicePath, this.file) DevFSEntry(this.devicePath, this.file)
...@@ -30,10 +38,13 @@ class DevFSEntry { ...@@ -30,10 +38,13 @@ class DevFSEntry {
String get assetPath => bundleEntry.archivePath; String get assetPath => bundleEntry.archivePath;
final FileSystemEntity file; final FileSystemEntity file;
FileSystemEntity _linkTarget;
FileStat _fileStat; FileStat _fileStat;
// When we scanned for files, did this still exist? // When we scanned for files, did this still exist?
bool _exists = false; bool _exists = false;
DateTime get lastModified => _fileStat?.modified; DateTime get lastModified => _fileStat?.modified;
bool get _isSourceEntry => file == null;
bool get _isAssetEntry => bundleEntry != null;
bool get stillExists { bool get stillExists {
if (_isSourceEntry) if (_isSourceEntry)
return true; return true;
...@@ -67,19 +78,28 @@ class DevFSEntry { ...@@ -67,19 +78,28 @@ class DevFSEntry {
void _stat() { void _stat() {
if (_isSourceEntry) if (_isSourceEntry)
return; return;
if (_linkTarget != null) {
// Stat the cached symlink target.
_fileStat = _linkTarget.statSync();
return;
}
_fileStat = file.statSync(); _fileStat = file.statSync();
if (_fileStat.type == FileSystemEntityType.LINK) { if (_fileStat.type == FileSystemEntityType.LINK) {
// Stat the link target. // Resolve, stat, and maybe cache the symlink target.
String resolved = file.resolveSymbolicLinksSync(); String resolved = file.resolveSymbolicLinksSync();
_fileStat = FileStat.statSync(resolved); FileSystemEntity linkTarget = new File(resolved);
// Stat the link target.
_fileStat = linkTarget.statSync();
if (devFSConfig.cacheSymlinks) {
_linkTarget = linkTarget;
}
} }
} }
bool get _isSourceEntry => file == null;
bool get _isAssetEntry => bundleEntry != null;
File _getFile() { File _getFile() {
if (_linkTarget != null) {
return _linkTarget;
}
if (file is Link) { if (file is Link) {
// The link target. // The link target.
return new File(file.resolveSymbolicLinksSync()); return new File(file.resolveSymbolicLinksSync());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment