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
23032d77
Unverified
Commit
23032d77
authored
Aug 25, 2020
by
Jonah Williams
Committed by
GitHub
Aug 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] refactor artifact downloading to retry zip exceptions. (#64512)
parent
39d7a019
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
471 additions
and
293 deletions
+471
-293
error_handling_file_system.dart
...lutter_tools/lib/src/base/error_handling_file_system.dart
+10
-0
cache.dart
packages/flutter_tools/lib/src/cache.dart
+204
-159
artifact_updater_test.dart
...utter_tools/test/general.shard/artifact_updater_test.dart
+180
-0
error_handling_file_system_test.dart
...t/general.shard/base/error_handling_file_system_test.dart
+19
-3
cache_test.dart
packages/flutter_tools/test/general.shard/cache_test.dart
+58
-122
testbed.dart
packages/flutter_tools/test/src/testbed.dart
+0
-9
No files found.
packages/flutter_tools/lib/src/base/error_handling_file_system.dart
View file @
23032d77
...
...
@@ -266,6 +266,16 @@ class ErrorHandlingDirectory
Link
childLink
(
String
basename
)
=>
wrapLink
(
fileSystem
.
directory
(
delegate
).
childLink
(
basename
));
@override
void
createSync
({
bool
recursive
=
false
})
{
return
_runSync
<
void
>(
()
=>
delegate
.
createSync
(
recursive:
recursive
),
platform:
_platform
,
failureMessage:
'Flutter failed to create a directory at "
${delegate.path}
"'
,
);
}
@override
Future
<
Directory
>
createTemp
([
String
prefix
])
{
return
_run
<
Directory
>(
...
...
packages/flutter_tools/lib/src/cache.dart
View file @
23032d77
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/artifact_updater_test.dart
0 → 100644
View file @
23032d77
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:file/memory.dart'
;
import
'package:file/src/interface/file.dart'
;
import
'package:file_testing/file_testing.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/net.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../src/common.dart'
;
void
main
(
)
{
testWithoutContext
(
'ArtifactUpdater can download a zip archive'
,
()
async
{
final
FakeNet
net
=
FakeNet
();
final
MockOperatingSystemUtils
operatingSystemUtils
=
MockOperatingSystemUtils
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
ArtifactUpdater
artifactUpdater
=
ArtifactUpdater
(
fileSystem:
fileSystem
,
logger:
logger
,
net:
net
,
operatingSystemUtils:
operatingSystemUtils
,
tempStorage:
fileSystem
.
currentDirectory
.
childDirectory
(
'temp'
)
..
createSync
(),
);
await
artifactUpdater
.
downloadZipArchive
(
'test message'
,
Uri
.
parse
(
'http:///test.zip'
),
fileSystem
.
currentDirectory
.
childDirectory
(
'out'
),
);
expect
(
logger
.
statusText
,
contains
(
'test message'
));
expect
(
fileSystem
.
file
(
'out/test'
),
exists
);
});
testWithoutContext
(
'ArtifactUpdater will de-download a file if unzipping fails'
,
()
async
{
final
FakeNet
net
=
FakeNet
();
final
MockOperatingSystemUtils
operatingSystemUtils
=
MockOperatingSystemUtils
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
ArtifactUpdater
artifactUpdater
=
ArtifactUpdater
(
fileSystem:
fileSystem
,
logger:
logger
,
net:
net
,
operatingSystemUtils:
operatingSystemUtils
,
tempStorage:
fileSystem
.
currentDirectory
.
childDirectory
(
'temp'
)
..
createSync
(),
);
operatingSystemUtils
.
failures
=
1
;
await
artifactUpdater
.
downloadZipArchive
(
'test message'
,
Uri
.
parse
(
'http:///test.zip'
),
fileSystem
.
currentDirectory
.
childDirectory
(
'out'
),
);
expect
(
logger
.
statusText
,
contains
(
'test message'
));
expect
(
fileSystem
.
file
(
'out/test'
),
exists
);
expect
(
net
.
attempts
,
2
);
});
testWithoutContext
(
'ArtifactUpdater will bail if unzipping fails more than twice'
,
()
async
{
final
FakeNet
net
=
FakeNet
();
final
MockOperatingSystemUtils
operatingSystemUtils
=
MockOperatingSystemUtils
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
ArtifactUpdater
artifactUpdater
=
ArtifactUpdater
(
fileSystem:
fileSystem
,
logger:
logger
,
net:
net
,
operatingSystemUtils:
operatingSystemUtils
,
tempStorage:
fileSystem
.
currentDirectory
.
childDirectory
(
'temp'
)
..
createSync
(),
);
operatingSystemUtils
.
failures
=
2
;
expect
(
artifactUpdater
.
downloadZipArchive
(
'test message'
,
Uri
.
parse
(
'http:///test.zip'
),
fileSystem
.
currentDirectory
.
childDirectory
(
'out'
),
),
throwsA
(
isA
<
ProcessException
>()));
expect
(
fileSystem
.
file
(
'te,[/test'
),
isNot
(
exists
));
expect
(
fileSystem
.
file
(
'out/test'
),
isNot
(
exists
));
});
testWithoutContext
(
'ArtifactUpdater can download a tar archive'
,
()
async
{
final
FakeNet
net
=
FakeNet
();
final
MockOperatingSystemUtils
operatingSystemUtils
=
MockOperatingSystemUtils
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
ArtifactUpdater
artifactUpdater
=
ArtifactUpdater
(
fileSystem:
fileSystem
,
logger:
logger
,
net:
net
,
operatingSystemUtils:
operatingSystemUtils
,
tempStorage:
fileSystem
.
currentDirectory
.
childDirectory
(
'temp'
)
..
createSync
(),
);
await
artifactUpdater
.
downloadZippedTarball
(
'test message'
,
Uri
.
parse
(
'http:///test.zip'
),
fileSystem
.
currentDirectory
.
childDirectory
(
'out'
),
);
expect
(
fileSystem
.
file
(
'out/test'
),
exists
);
});
testWithoutContext
(
'ArtifactUpdater will delete downloaded files if they exist.'
,
()
async
{
final
FakeNet
net
=
FakeNet
();
final
MockOperatingSystemUtils
operatingSystemUtils
=
MockOperatingSystemUtils
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
ArtifactUpdater
artifactUpdater
=
ArtifactUpdater
(
fileSystem:
fileSystem
,
logger:
logger
,
net:
net
,
operatingSystemUtils:
operatingSystemUtils
,
tempStorage:
fileSystem
.
currentDirectory
.
childDirectory
(
'temp'
)
..
createSync
(),
);
artifactUpdater
.
downloadedFiles
.
addAll
(<
File
>[
fileSystem
.
file
(
'a/b/c/d'
)..
createSync
(
recursive:
true
),
fileSystem
.
file
(
'd/e/f'
),
]);
artifactUpdater
.
removeDownloadedFiles
();
expect
(
fileSystem
.
file
(
'a/b/c/d'
),
isNot
(
exists
));
expect
(
logger
.
errorText
,
isEmpty
);
});
}
class
FakeNet
implements
Net
{
int
attempts
=
0
;
@override
Future
<
bool
>
doesRemoteFileExist
(
Uri
url
)
async
{
return
true
;
}
@override
Future
<
List
<
int
>>
fetchUrl
(
Uri
url
,
{
int
maxAttempts
,
File
destFile
})
async
{
attempts
+=
1
;
if
(
destFile
!=
null
)
{
destFile
.
createSync
();
return
null
;
}
return
<
int
>[];
}
}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{
int
failures
=
0
;
@override
void
unzip
(
File
file
,
Directory
targetDirectory
)
{
if
(
failures
>
0
)
{
failures
-=
1
;
throw
const
ProcessException
(
'zip'
,
<
String
>[],
'Failed to unzip'
);
}
targetDirectory
.
childFile
(
file
.
fileSystem
.
path
.
basenameWithoutExtension
(
file
.
path
))
.
createSync
();
}
@override
void
unpack
(
File
gzippedTarFile
,
Directory
targetDirectory
)
{
if
(
failures
>
0
)
{
failures
-=
1
;
throw
const
ProcessException
(
'zip'
,
<
String
>[],
'Failed to unzip'
);
}
targetDirectory
.
childFile
(
gzippedTarFile
.
fileSystem
.
path
.
basenameWithoutExtension
(
gzippedTarFile
.
path
))
.
createSync
();
}
}
packages/flutter_tools/test/general.shard/base/error_handling_file_system_test.dart
View file @
23032d77
...
...
@@ -64,7 +64,7 @@ void setupWriteMocks({
)).
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
}
void
setup
CreateTemp
Mocks
(
{
void
setup
Directory
Mocks
(
{
FileSystem
mockFileSystem
,
ErrorHandlingFileSystem
fs
,
int
errorCode
,
...
...
@@ -76,6 +76,8 @@ void setupCreateTempMocks({
});
when
(
mockDirectory
.
createTempSync
(
any
))
.
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
when
(
mockDirectory
.
createSync
(
recursive:
anyNamed
(
'recursive'
)))
.
thenThrow
(
FileSystemException
(
''
,
''
,
OSError
(
''
,
errorCode
)));
}
void
main
(
)
{
...
...
@@ -158,7 +160,7 @@ void main() {
});
testWithoutContext
(
'when creating a temporary dir on a full device'
,
()
async
{
setup
CreateTemp
Mocks
(
setup
Directory
Mocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kDeviceFull
,
...
...
@@ -172,6 +174,20 @@ void main() {
expect
(()
=>
directory
.
createTempSync
(
'prefix'
),
throwsToolExit
(
message:
expectedMessage
));
});
testWithoutContext
(
'when creating a directory with permission issues'
,
()
async
{
setupDirectoryMocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
kUserPermissionDenied
,
);
final
Directory
directory
=
fs
.
directory
(
'directory'
);
const
String
expectedMessage
=
'Flutter failed to create a directory at'
;
expect
(()
=>
directory
.
createSync
(
recursive:
true
),
throwsToolExit
(
message:
expectedMessage
));
});
});
group
(
'throws ToolExit on Linux'
,
()
{
...
...
@@ -209,7 +225,7 @@ void main() {
});
testWithoutContext
(
'when creating a temporary dir on a full device'
,
()
async
{
setup
CreateTemp
Mocks
(
setup
Directory
Mocks
(
mockFileSystem:
mockFileSystem
,
fs:
fs
,
errorCode:
enospc
,
...
...
packages/flutter_tools/test/general.shard/cache_test.dart
View file @
23032d77
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/src/testbed.dart
View file @
23032d77
...
...
@@ -915,11 +915,6 @@ class FakeCache implements Cache {
throw
UnsupportedError
(
'Not supported in the fake Cache'
);
}
@override
Future
<
String
>
getThirdPartyFile
(
String
urlStr
,
String
serviceName
)
{
throw
UnsupportedError
(
'Not supported in the fake Cache'
);
}
@override
String
getVersionFor
(
String
artifactName
)
{
throw
UnsupportedError
(
'Not supported in the fake Cache'
);
...
...
@@ -949,10 +944,6 @@ class FakeCache implements Cache {
Future
<
void
>
updateAll
(
Set
<
DevelopmentArtifact
>
requiredArtifacts
)
async
{
}
@override
Future
<
void
>
downloadFile
(
Uri
url
,
File
location
)
async
{
}
@override
Future
<
bool
>
doesRemoteExist
(
String
message
,
Uri
url
)
async
{
return
true
;
...
...
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