Unverified Commit 77e15103 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Catch failure to create directory in cache (#37871)

parent 361730ed
......@@ -398,7 +398,15 @@ abstract class CachedArtifact {
return;
}
if (!location.existsSync()) {
location.createSync(recursive: true);
try {
location.createSync(recursive: true);
} on FileSystemException catch (err) {
printError(err.toString());
throwToolExit(
'Failed to create directory for flutter cache at ${location.path}. '
'Flutter may be missing permissions in its cache directory.'
);
}
}
await updateInner();
cache.setStampFor(stampName, version);
......
......@@ -243,6 +243,27 @@ void main() {
Platform: () => fakePlatform,
});
});
testUsingContext('throws tool exit on fs exception', () async {
final FakeCachedArtifact fakeCachedArtifact = FakeCachedArtifact(
cache: MockCache(),
requiredArtifacts: <DevelopmentArtifact>{
DevelopmentArtifact.android,
}
);
final Directory mockDirectory = MockDirectory();
when(fakeCachedArtifact.cache.getArtifactDirectory(any))
.thenReturn(mockDirectory);
when(mockDirectory.existsSync()).thenReturn(false);
when(mockDirectory.createSync(recursive: true))
.thenThrow(const FileSystemException());
expect(() => fakeCachedArtifact.update(<DevelopmentArtifact>{
DevelopmentArtifact.android,
}), throwsA(isInstanceOf<ToolExit>()));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
});
}
class FakeCachedArtifact extends EngineCachedArtifact {
......@@ -271,6 +292,7 @@ class FakeCachedArtifact extends EngineCachedArtifact {
class MockFileSystem extends Mock implements FileSystem {}
class MockFile extends Mock implements File {}
class MockDirectory extends Mock implements Directory {}
class MockRandomAccessFile extends Mock implements RandomAccessFile {}
class MockCachedArtifact extends Mock implements CachedArtifact {}
......
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