Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
6fddb7ee
Unverified
Commit
6fddb7ee
authored
Apr 02, 2020
by
Zachary Anderson
Committed by
GitHub
Apr 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Handle full device when creating a temp directory (#53691)
parent
3a0d8377
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
407 additions
and
151 deletions
+407
-151
error_handling_file_system.dart
...lutter_tools/lib/src/base/error_handling_file_system.dart
+216
-75
globals.dart
packages/flutter_tools/lib/src/globals.dart
+2
-1
error_handling_file_system_test.dart
...t/general.shard/base/error_handling_file_system_test.dart
+189
-75
No files found.
packages/flutter_tools/lib/src/base/error_handling_file_system.dart
View file @
6fddb7ee
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/globals.dart
View file @
6fddb7ee
...
...
@@ -52,7 +52,8 @@ const FileSystem _kLocalFs = LocalFileSystem();
/// By default it uses local disk-based implementation. Override this in tests
/// with [MemoryFileSystem].
FileSystem
get
fs
=>
ErrorHandlingFileSystem
(
context
.
get
<
FileSystem
>()
??
_kLocalFs
,
delegate:
context
.
get
<
FileSystem
>()
??
_kLocalFs
,
platform:
platform
,
);
final
FileSystemUtils
_defaultFileSystemUtils
=
FileSystemUtils
(
...
...
packages/flutter_tools/test/general.shard/base/error_handling_file_system_test.dart
View file @
6fddb7ee
...
...
@@ -10,8 +10,6 @@ import 'package:platform/platform.dart';
import
'package:path/path.dart'
as
path
;
// ignore: package_path_import
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/testbed.dart'
;
class
MockFile
extends
Mock
implements
File
{}
class
MockFileSystem
extends
Mock
implements
FileSystem
{}
...
...
@@ -23,29 +21,16 @@ final Platform windowsPlatform = FakePlatform(
environment:
<
String
,
String
>{}
);
void
main
(
)
{
group
(
'throws ToolExit on Windows'
,
()
{
const
int
kDeviceFull
=
112
;
const
int
kUserMappedSectionOpened
=
1224
;
Testbed
testbed
;
MockFileSystem
mockFileSystem
;
ErrorHandlingFileSystem
fs
;
setUp
(()
{
mockFileSystem
=
MockFileSystem
();
fs
=
ErrorHandlingFileSystem
(
mockFileSystem
);
when
(
mockFileSystem
.
path
).
thenReturn
(
MockPathContext
());
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
windowsPlatform
,
});
});
final
Platform
linuxPlatform
=
FakePlatform
(
operatingSystem:
'linux'
,
environment:
<
String
,
String
>{}
);
void
writeTests
({
String
testName
,
void
setupWriteMocks
(
{
FileSystem
mockFileSystem
,
ErrorHandlingFileSystem
fs
,
int
errorCode
,
String
expectedMessage
,
})
{
test
(
testName
,
()
=>
testbed
.
run
(()
async
{
})
{
final
MockFile
mockFile
=
MockFile
();
when
(
mockFileSystem
.
file
(
any
)).
thenReturn
(
mockFile
);
when
(
mockFile
.
writeAsBytes
(
...
...
@@ -74,9 +59,48 @@ void main() {
encoding:
anyNamed
(
'encoding'
),
flush:
anyNamed
(
'flush'
),
)).
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
}
void
setupCreateTempMocks
(
{
FileSystem
mockFileSystem
,
ErrorHandlingFileSystem
fs
,
int
errorCode
,
})
{
final
MockDirectory
mockDirectory
=
MockDirectory
();
when
(
mockFileSystem
.
directory
(
any
)).
thenReturn
(
mockDirectory
);
when
(
mockDirectory
.
createTemp
(
any
)).
thenAnswer
((
_
)
async
{
throw
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
));
});
when
(
mockDirectory
.
createTempSync
(
any
))
.
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
}
void
main
(
)
{
group
(
'throws ToolExit on Windows'
,
()
{
const
int
kDeviceFull
=
112
;
const
int
kUserMappedSectionOpened
=
1224
;
MockFileSystem
mockFileSystem
;
ErrorHandlingFileSystem
fs
;
setUp
(()
{
mockFileSystem
=
MockFileSystem
();
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
platform:
windowsPlatform
,
);
when
(
mockFileSystem
.
path
).
thenReturn
(
MockPathContext
());
});
testWithoutContext
(
'when writing to a full device'
,
()
async
{
setupWriteMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kDeviceFull
,
);
final
File
file
=
fs
.
file
(
'file'
);
const
String
expectedMessage
=
'The target device is full'
;
expect
(()
async
=>
await
file
.
writeAsBytes
(<
int
>[
0
]),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
async
=>
await
file
.
writeAsString
(
''
),
...
...
@@ -85,31 +109,112 @@ void main() {
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
file
.
writeAsStringSync
(
''
),
throwsToolExit
(
message:
expectedMessage
));
}));
}
});
testWithoutContext
(
'when the file is being used by another program'
,
()
async
{
setupWriteMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kUserMappedSectionOpened
,
);
final
File
file
=
fs
.
file
(
'file'
);
writeTests
(
testName:
'when writing to a full device'
,
const
String
expectedMessage
=
'The file is being used by another program'
;
expect
(()
async
=>
await
file
.
writeAsBytes
(<
int
>[
0
]),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
async
=>
await
file
.
writeAsString
(
''
),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
file
.
writeAsBytesSync
(<
int
>[
0
]),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
file
.
writeAsStringSync
(
''
),
throwsToolExit
(
message:
expectedMessage
));
});
testWithoutContext
(
'when creating a temporary dir on a full device'
,
()
async
{
setupCreateTempMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kDeviceFull
,
expectedMessage:
'The target device is full'
,
);
writeTests
(
testName:
'when the file is being used by another program'
,
errorCode:
kUserMappedSectionOpened
,
expectedMessage:
'The file is being used by another program'
,
final
Directory
directory
=
fs
.
directory
(
'directory'
);
const
String
expectedMessage
=
'The target device is full'
;
expect
(()
async
=>
await
directory
.
createTemp
(
'prefix'
),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
directory
.
createTempSync
(
'prefix'
),
throwsToolExit
(
message:
expectedMessage
));
});
});
group
(
'throws ToolExit on Linux'
,
()
{
const
int
enospc
=
28
;
MockFileSystem
mockFileSystem
;
ErrorHandlingFileSystem
fs
;
setUp
(()
{
mockFileSystem
=
MockFileSystem
();
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
platform:
linuxPlatform
,
);
when
(
mockFileSystem
.
path
).
thenReturn
(
MockPathContext
());
});
testWithoutContext
(
'when writing to a full device'
,
()
async
{
setupWriteMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
enospc
,
);
final
File
file
=
fs
.
file
(
'file'
);
const
String
expectedMessage
=
'The target device is full'
;
expect
(()
async
=>
await
file
.
writeAsBytes
(<
int
>[
0
]),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
async
=>
await
file
.
writeAsString
(
''
),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
file
.
writeAsBytesSync
(<
int
>[
0
]),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
file
.
writeAsStringSync
(
''
),
throwsToolExit
(
message:
expectedMessage
));
});
testWithoutContext
(
'when creating a temporary dir on a full device'
,
()
async
{
setupCreateTempMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
enospc
,
);
final
Directory
directory
=
fs
.
directory
(
'directory'
);
const
String
expectedMessage
=
'The target device is full'
;
expect
(()
async
=>
await
directory
.
createTemp
(
'prefix'
),
throwsToolExit
(
message:
expectedMessage
));
expect
(()
=>
directory
.
createTempSync
(
'prefix'
),
throwsToolExit
(
message:
expectedMessage
));
});
});
test
(
'Caches path context correctly'
,
()
{
test
WithoutContext
(
'Caches path context correctly'
,
()
{
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
mockFileSystem
);
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
platform:
const
LocalPlatform
(),
);
expect
(
identical
(
fs
.
path
,
fs
.
path
),
true
);
});
test
(
'Clears cache when CWD changes'
,
()
{
test
WithoutContext
(
'Clears cache when CWD changes'
,
()
{
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
mockFileSystem
);
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
platform:
const
LocalPlatform
(),
);
final
Object
firstPath
=
fs
.
path
;
...
...
@@ -119,8 +224,11 @@ void main() {
expect
(
identical
(
firstPath
,
fs
.
path
),
false
);
});
test
(
'Throws type error if Directory type is set to curentDirectory with LocalFileSystem'
,
()
{
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
const
LocalFileSystem
());
testWithoutContext
(
'Throws type error if Directory type is set to curentDirectory with LocalFileSystem'
,
()
{
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
const
LocalFileSystem
(),
platform:
const
LocalPlatform
(),
);
final
MockDirectory
directory
=
MockDirectory
();
when
(
directory
.
path
).
thenReturn
(
'path'
);
...
...
@@ -128,17 +236,23 @@ void main() {
});
group
(
'toString() gives toString() of delegate'
,
()
{
test
(
'ErrorHandlingFileSystem'
,
()
{
test
WithoutContext
(
'ErrorHandlingFileSystem'
,
()
{
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
mockFileSystem
);
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
platform:
const
LocalPlatform
(),
);
expect
(
mockFileSystem
.
toString
(),
isNotNull
);
expect
(
fs
.
toString
(),
equals
(
mockFileSystem
.
toString
()));
});
test
(
'ErrorHandlingFile'
,
()
{
test
WithoutContext
(
'ErrorHandlingFile'
,
()
{
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
mockFileSystem
);
final
FileSystem
fs
=
ErrorHandlingFileSystem
(
delegate:
mockFileSystem
,
platform:
const
LocalPlatform
(),
);
final
MockFile
mockFile
=
MockFile
();
when
(
mockFileSystem
.
file
(
any
)).
thenReturn
(
mockFile
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment