mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Support caching host filesystem symlink targets to speedup DevFS updates (#6798)
This commit is contained in:
parent
bbf98d9c6b
commit
11ca0f1ada
@ -35,6 +35,7 @@ import 'src/commands/test.dart';
|
||||
import 'src/commands/trace.dart';
|
||||
import 'src/commands/update_packages.dart';
|
||||
import 'src/commands/upgrade.dart';
|
||||
import 'src/devfs.dart';
|
||||
import 'src/device.dart';
|
||||
import 'src/doctor.dart';
|
||||
import 'src/globals.dart';
|
||||
@ -83,6 +84,7 @@ Future<Null> main(List<String> args) async {
|
||||
// Initialize globals.
|
||||
context[Logger] = new StdoutLogger();
|
||||
context[DeviceManager] = new DeviceManager();
|
||||
context[DevFSConfig] = new DevFSConfig();
|
||||
Doctor.initGlobal();
|
||||
|
||||
dynamic result = await runner.run(args);
|
||||
|
@ -8,6 +8,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'base/context.dart';
|
||||
import 'build_info.dart';
|
||||
import 'dart/package_map.dart';
|
||||
import 'asset.dart';
|
||||
@ -16,6 +17,13 @@ import 'vmservice.dart';
|
||||
|
||||
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.
|
||||
class DevFSEntry {
|
||||
DevFSEntry(this.devicePath, this.file)
|
||||
@ -30,10 +38,13 @@ class DevFSEntry {
|
||||
String get assetPath => bundleEntry.archivePath;
|
||||
|
||||
final FileSystemEntity file;
|
||||
FileSystemEntity _linkTarget;
|
||||
FileStat _fileStat;
|
||||
// When we scanned for files, did this still exist?
|
||||
bool _exists = false;
|
||||
DateTime get lastModified => _fileStat?.modified;
|
||||
bool get _isSourceEntry => file == null;
|
||||
bool get _isAssetEntry => bundleEntry != null;
|
||||
bool get stillExists {
|
||||
if (_isSourceEntry)
|
||||
return true;
|
||||
@ -67,19 +78,28 @@ class DevFSEntry {
|
||||
void _stat() {
|
||||
if (_isSourceEntry)
|
||||
return;
|
||||
if (_linkTarget != null) {
|
||||
// Stat the cached symlink target.
|
||||
_fileStat = _linkTarget.statSync();
|
||||
return;
|
||||
}
|
||||
_fileStat = file.statSync();
|
||||
if (_fileStat.type == FileSystemEntityType.LINK) {
|
||||
// Stat the link target.
|
||||
// Resolve, stat, and maybe cache the symlink target.
|
||||
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() {
|
||||
if (_linkTarget != null) {
|
||||
return _linkTarget;
|
||||
}
|
||||
if (file is Link) {
|
||||
// The link target.
|
||||
return new File(file.resolveSymbolicLinksSync());
|
||||
|
Loading…
Reference in New Issue
Block a user