Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit f767f86

Browse files
authored
check if directory exists before listing content (#119748)
1 parent 322d10e commit f767f86

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

packages/flutter_tools/lib/src/cache.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,10 @@ class ArtifactUpdater {
12421242
continue;
12431243
}
12441244
for (Directory directory = file.parent; directory.absolute.path != _tempStorage.absolute.path; directory = directory.parent) {
1245+
// Handle race condition when the directory is deleted before this step
1246+
if (!directory.existsSync()) {
1247+
break;
1248+
}
12451249
if (directory.listSync().isNotEmpty) {
12461250
break;
12471251
}

packages/flutter_tools/test/general.shard/cache_test.dart

+40
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,30 @@ void main() {
398398
expect(staleFile, isNot(exists));
399399
});
400400

401+
testWithoutContext('Try to remove without a parent', () async {
402+
final FileSystem fileSystem = MemoryFileSystem.test();
403+
final Directory parent = fileSystem.directory('dir');
404+
parent.createSync();
405+
final Directory child = parent.childDirectory('child');
406+
child.createSync();
407+
final Directory tempStorage = parent.childDirectory('temp');
408+
tempStorage.createSync();
409+
final FakeArtifactUpdaterDownload fakeArtifact = FakeArtifactUpdaterDownload(
410+
operatingSystemUtils: FakeOperatingSystemUtils(),
411+
logger: BufferLogger.test(),
412+
fileSystem: fileSystem,
413+
tempStorage: tempStorage,
414+
httpClient: HttpClient(),
415+
platform: FakePlatform(),
416+
allowedBaseUrls: <String>[]
417+
);
418+
final File file = child.childFile('file');
419+
file.createSync();
420+
fakeArtifact.addFiles(<File>[file]);
421+
child.deleteSync(recursive: true);
422+
fakeArtifact.removeDownloadedFiles();
423+
});
424+
401425
testWithoutContext('IosUsbArtifacts verifies executables for libimobiledevice in isUpToDateInner', () async {
402426
final FileSystem fileSystem = MemoryFileSystem.test();
403427
final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any());
@@ -1212,3 +1236,19 @@ class FakeArtifactUpdater extends Fake implements ArtifactUpdater {
12121236
@override
12131237
void removeDownloadedFiles() { }
12141238
}
1239+
1240+
class FakeArtifactUpdaterDownload extends ArtifactUpdater {
1241+
FakeArtifactUpdaterDownload({
1242+
required super.operatingSystemUtils,
1243+
required super.logger,
1244+
required super.fileSystem,
1245+
required super.tempStorage,
1246+
required super.httpClient,
1247+
required super.platform,
1248+
required super.allowedBaseUrls
1249+
});
1250+
1251+
void addFiles(List<File> files) {
1252+
downloadedFiles.addAll(files);
1253+
}
1254+
}

0 commit comments

Comments
 (0)