Unverified Commit 8de72126 authored by Jia Hao's avatar Jia Hao Committed by GitHub

[flutter_tools] Don't fail copying files if the destination is not writable (#71215)

parent 9806865b
...@@ -289,10 +289,7 @@ class ErrorHandlingFile ...@@ -289,10 +289,7 @@ class ErrorHandlingFile
// Next check if the destination file can be written. If not, bail through // Next check if the destination file can be written. If not, bail through
// error handling. // error handling.
_runSync<void>( _runSync<void>(
() { () => resultFile.createSync(recursive: true),
resultFile.createSync(recursive: true);
resultFile.openSync(mode: FileMode.writeOnly).closeSync();
},
platform: _platform, platform: _platform,
failureMessage: 'Flutter failed to copy $path to $newPath due to destination location error' failureMessage: 'Flutter failed to copy $path to $newPath due to destination location error'
); );
......
...@@ -817,12 +817,12 @@ void main() { ...@@ -817,12 +817,12 @@ void main() {
expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit()); expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit());
}); });
testWithoutContext('copySync handles error if openSync on destination file fails', () { testWithoutContext('copySync handles error if createSync on destination file fails', () {
final MockFile source = MockFile(); final MockFile source = MockFile();
final MockFile dest = MockFile(); final MockFile dest = MockFile();
when(source.openSync(mode: anyNamed('mode'))) when(source.openSync(mode: anyNamed('mode')))
.thenReturn(MockRandomAccessFile()); .thenReturn(MockRandomAccessFile());
when(dest.openSync(mode: anyNamed('mode'))) when(dest.createSync(recursive: anyNamed('recursive')))
.thenThrow(const FileSystemException('', '', OSError('', eaccess))); .thenThrow(const FileSystemException('', '', OSError('', eaccess)));
when(mockFileSystem.file('source')).thenReturn(source); when(mockFileSystem.file('source')).thenReturn(source);
when(mockFileSystem.file('dest')).thenReturn(dest); when(mockFileSystem.file('dest')).thenReturn(dest);
...@@ -830,6 +830,24 @@ void main() { ...@@ -830,6 +830,24 @@ void main() {
expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit()); expect(() => fileSystem.file('source').copySync('dest'), throwsToolExit());
}); });
// dart:io is able to clobber read-only files.
testWithoutContext('copySync will copySync even if the destination is not writable', () {
final MockFile source = MockFile();
final MockFile dest = MockFile();
when(source.copySync(any)).thenReturn(dest);
when(mockFileSystem.file('source')).thenReturn(source);
when(source.openSync(mode: anyNamed('mode')))
.thenReturn(MockRandomAccessFile());
when(mockFileSystem.file('dest')).thenReturn(dest);
when(dest.openSync(mode: FileMode.writeOnly))
.thenThrow(const FileSystemException('', '', OSError('', eaccess)));
fileSystem.file('source').copySync('dest');
verify(source.copySync('dest')).called(1);
});
testWithoutContext('copySync will copySync if there are no exceptions', () { testWithoutContext('copySync will copySync if there are no exceptions', () {
final MockFile source = MockFile(); final MockFile source = MockFile();
final MockFile dest = MockFile(); final MockFile dest = MockFile();
......
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