check if directory exists before listing content (#119748)
This commit is contained in:
@@ -1242,6 +1242,10 @@ class ArtifactUpdater {
|
||||
continue;
|
||||
}
|
||||
for (Directory directory = file.parent; directory.absolute.path != _tempStorage.absolute.path; directory = directory.parent) {
|
||||
// Handle race condition when the directory is deleted before this step
|
||||
if (!directory.existsSync()) {
|
||||
break;
|
||||
}
|
||||
if (directory.listSync().isNotEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -398,6 +398,30 @@ void main() {
|
||||
expect(staleFile, isNot(exists));
|
||||
});
|
||||
|
||||
testWithoutContext('Try to remove without a parent', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Directory parent = fileSystem.directory('dir');
|
||||
parent.createSync();
|
||||
final Directory child = parent.childDirectory('child');
|
||||
child.createSync();
|
||||
final Directory tempStorage = parent.childDirectory('temp');
|
||||
tempStorage.createSync();
|
||||
final FakeArtifactUpdaterDownload fakeArtifact = FakeArtifactUpdaterDownload(
|
||||
operatingSystemUtils: FakeOperatingSystemUtils(),
|
||||
logger: BufferLogger.test(),
|
||||
fileSystem: fileSystem,
|
||||
tempStorage: tempStorage,
|
||||
httpClient: HttpClient(),
|
||||
platform: FakePlatform(),
|
||||
allowedBaseUrls: <String>[]
|
||||
);
|
||||
final File file = child.childFile('file');
|
||||
file.createSync();
|
||||
fakeArtifact.addFiles(<File>[file]);
|
||||
child.deleteSync(recursive: true);
|
||||
fakeArtifact.removeDownloadedFiles();
|
||||
});
|
||||
|
||||
testWithoutContext('IosUsbArtifacts verifies executables for libimobiledevice in isUpToDateInner', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any());
|
||||
@@ -1212,3 +1236,19 @@ class FakeArtifactUpdater extends Fake implements ArtifactUpdater {
|
||||
@override
|
||||
void removeDownloadedFiles() { }
|
||||
}
|
||||
|
||||
class FakeArtifactUpdaterDownload extends ArtifactUpdater {
|
||||
FakeArtifactUpdaterDownload({
|
||||
required super.operatingSystemUtils,
|
||||
required super.logger,
|
||||
required super.fileSystem,
|
||||
required super.tempStorage,
|
||||
required super.httpClient,
|
||||
required super.platform,
|
||||
required super.allowedBaseUrls
|
||||
});
|
||||
|
||||
void addFiles(List<File> files) {
|
||||
downloadedFiles.addAll(files);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user