Delete any existing version of a DevFS file before overwriting the file

Consumers of the file may have open file mappings, and those mappings must not
see a mix of old and new content as the new file is written.

Fixes https://github.com/flutter/flutter/issues/21858

Change-Id: Ia4d6cee53cceaa04bec01a2af56c76fad05dcad8
Reviewed-on: https://dart-review.googlesource.com/75620
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
Jason Simmons 2018-09-19 21:43:19 +00:00 committed by commit-bot@chromium.org
parent 7763ec3cd1
commit 3463f94ed9

View file

@ -94,6 +94,9 @@ class PendingWrite {
var file = new File.fromUri(uri);
var parent_directory = file.parent;
await parent_directory.create(recursive: true);
if (await file.exists()) {
await file.delete();
}
var result = await file.writeAsBytes(bytes);
completer.complete(null);
WriteLimiter._writeCompleted();
@ -143,6 +146,9 @@ Future writeStreamFileCallback(Uri path, Stream<List<int>> bytes) async {
var file = new File.fromUri(path);
var parent_directory = file.parent;
await parent_directory.create(recursive: true);
if (await file.exists()) {
await file.delete();
}
IOSink sink = await file.openWrite();
await sink.addStream(bytes);
await sink.close();