Use XDG_CONFIG_HOME dir by default for config files (#66645)
This PR changes the Config class in flutter_tools to use the XDG Base directory specification instead of putting files directly in the user's home directory. If those files are already present in the home directory, they are used instead.
This commit is contained in:
@@ -65,7 +65,7 @@ void main() {
|
||||
|
||||
testWithoutContext('Config parse error', () {
|
||||
final BufferLogger bufferLogger = BufferLogger.test();
|
||||
final File file = memoryFileSystem.file('example')
|
||||
final File file = memoryFileSystem.file('.flutter_example')
|
||||
..writeAsStringSync('{"hello":"bar');
|
||||
config = Config(
|
||||
'example',
|
||||
@@ -106,6 +106,30 @@ void main() {
|
||||
// Also contains original error message:
|
||||
expect(bufferLogger.errorText, contains('The flutter tool cannot access the file or directory'));
|
||||
});
|
||||
|
||||
testWithoutContext('Config in home dir is used if it exists', () {
|
||||
memoryFileSystem.file('.flutter_example').writeAsStringSync('{"hello":"bar"}');
|
||||
config = Config(
|
||||
'example',
|
||||
fileSystem: memoryFileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: fakePlatform,
|
||||
);
|
||||
expect(config.getValue('hello'), 'bar');
|
||||
expect(memoryFileSystem.file('.config/flutter/example').existsSync(), false);
|
||||
});
|
||||
|
||||
testWithoutContext('Config is created in config dir if it does not already exist in home dir', () {
|
||||
config = Config(
|
||||
'example',
|
||||
fileSystem: memoryFileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: fakePlatform,
|
||||
);
|
||||
|
||||
config.setValue('foo', 'bar');
|
||||
expect(memoryFileSystem.file('.config/flutter/example').existsSync(), true);
|
||||
});
|
||||
}
|
||||
|
||||
class FakeFile extends Fake implements File {
|
||||
|
||||
Reference in New Issue
Block a user