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
94270759
Unverified
Commit
94270759
authored
Nov 22, 2019
by
xster
Committed by
GitHub
Nov 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "catch parse error from corrupt config (#45319)" (#45412)
parent
6640c8b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
55 deletions
+37
-55
config.dart
packages/flutter_tools/lib/src/base/config.dart
+2
-15
config_test.dart
packages/flutter_tools/test/general.shard/config_test.dart
+35
-40
No files found.
packages/flutter_tools/lib/src/base/config.dart
View file @
94270759
...
...
@@ -3,28 +3,15 @@
// found in the LICENSE file.
import
'../convert.dart'
;
import
'../globals.dart'
;
import
'context.dart'
;
import
'file_system.dart'
;
import
'logger.dart'
;
import
'utils.dart'
;
class
Config
{
Config
([
File
configFile
,
Logger
localLogger
])
{
final
Logger
loggerInstance
=
localLogger
??
logger
;
Config
([
File
configFile
])
{
_configFile
=
configFile
??
fs
.
file
(
fs
.
path
.
join
(
userHomePath
(),
'.flutter_settings'
));
if
(
_configFile
.
existsSync
())
{
try
{
_values
=
castStringKeyedMap
(
json
.
decode
(
_configFile
.
readAsStringSync
()));
}
on
FormatException
{
loggerInstance
..
printError
(
'Failed to decode preferences in
${_configFile.path}
.'
)
..
printError
(
'You may need to reapply any previously saved configuration '
'with the "flutter config" command.'
,
);
_configFile
.
deleteSync
();
}
_values
=
castStringKeyedMap
(
json
.
decode
(
_configFile
.
readAsStringSync
()));
}
}
...
...
packages/flutter_tools/test/general.shard/config_test.dart
View file @
94270759
...
...
@@ -2,59 +2,54 @@
// 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:flutter_tools/src/base/config.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'../src/common.dart'
;
void
main
(
)
{
Config
config
;
MemoryFileSystem
memoryFileSystem
;
Directory
tempDir
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
(
);
final
File
file
=
memoryFileSystem
.
file
(
'example'
);
tempDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_config_test.'
);
final
File
file
=
fs
.
file
(
fs
.
path
.
join
(
tempDir
.
path
,
'.settings'
)
);
config
=
Config
(
file
);
});
test
(
'Config get set value'
,
()
async
{
expect
(
config
.
getValue
(
'foo'
),
null
);
config
.
setValue
(
'foo'
,
'bar'
);
expect
(
config
.
getValue
(
'foo'
),
'bar'
);
expect
(
config
.
keys
,
contains
(
'foo'
));
});
test
(
'Config get set bool value'
,
()
async
{
expect
(
config
.
getValue
(
'foo'
),
null
);
config
.
setValue
(
'foo'
,
true
);
expect
(
config
.
getValue
(
'foo'
),
true
);
expect
(
config
.
keys
,
contains
(
'foo'
));
});
test
(
'Config containsKey'
,
()
async
{
expect
(
config
.
containsKey
(
'foo'
),
false
);
config
.
setValue
(
'foo'
,
'bar'
);
expect
(
config
.
containsKey
(
'foo'
),
true
);
tearDown
(()
{
tryToDelete
(
tempDir
);
});
test
(
'Config removeValue'
,
()
async
{
expect
(
config
.
getValue
(
'foo'
),
null
);
config
.
setValue
(
'foo'
,
'bar'
);
expect
(
config
.
getValue
(
'foo'
),
'bar'
);
expect
(
config
.
keys
,
contains
(
'foo'
));
config
.
removeValue
(
'foo'
);
expect
(
config
.
getValue
(
'foo'
),
null
);
expect
(
config
.
keys
,
isNot
(
contains
(
'foo'
)));
});
test
(
'Config parse error'
,
()
{
final
BufferLogger
bufferLogger
=
BufferLogger
();
final
File
file
=
memoryFileSystem
.
file
(
'example'
)
..
writeAsStringSync
(
'{"hello":"bar'
);
config
=
Config
(
file
,
bufferLogger
);
expect
(
file
.
existsSync
(),
false
);
expect
(
bufferLogger
.
errorText
,
contains
(
'Failed to decode preferences'
));
group
(
'config'
,
()
{
test
(
'get set value'
,
()
async
{
expect
(
config
.
getValue
(
'foo'
),
null
);
config
.
setValue
(
'foo'
,
'bar'
);
expect
(
config
.
getValue
(
'foo'
),
'bar'
);
expect
(
config
.
keys
,
contains
(
'foo'
));
});
test
(
'get set bool value'
,
()
async
{
expect
(
config
.
getValue
(
'foo'
),
null
);
config
.
setValue
(
'foo'
,
true
);
expect
(
config
.
getValue
(
'foo'
),
true
);
expect
(
config
.
keys
,
contains
(
'foo'
));
});
test
(
'containsKey'
,
()
async
{
expect
(
config
.
containsKey
(
'foo'
),
false
);
config
.
setValue
(
'foo'
,
'bar'
);
expect
(
config
.
containsKey
(
'foo'
),
true
);
});
test
(
'removeValue'
,
()
async
{
expect
(
config
.
getValue
(
'foo'
),
null
);
config
.
setValue
(
'foo'
,
'bar'
);
expect
(
config
.
getValue
(
'foo'
),
'bar'
);
expect
(
config
.
keys
,
contains
(
'foo'
));
config
.
removeValue
(
'foo'
);
expect
(
config
.
getValue
(
'foo'
),
null
);
expect
(
config
.
keys
,
isNot
(
contains
(
'foo'
)));
});
});
}
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