Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/path_provider/path_provider_linux/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.2.2

* Fixes getApplicationId() behavior on Linux when GLib development packages are not installed.
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.

## 2.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GioUtils {
/// Creates a default instance that uses the real libgio.
GioUtils() {
try {
_gio = DynamicLibrary.open('libgio-2.0.so');
_gio = DynamicLibrary.open('libgio-2.0.so.0');
} on ArgumentError {
_gio = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,23 @@ class PathProviderLinux extends PathProviderPlatform {
@override
Future<String?> getApplicationCachePath() async {
final directory = Directory(path.join(xdg.cacheHome.path, await _getId()));
if (!directory.existsSync()) {
await directory.create(recursive: true);
if (directory.existsSync()) {
return directory.path;
}

// Unlike for the application support path, the plugin didn't intentionally
// use the executable name as a directory for cache path in the past.
// However, it *unintentionally* did use it depending on which packages are
// installed, so fall back to it anyway.
// See: https://github.com/flutter/flutter/issues/186834
final legacyDirectory = Directory(
path.join(xdg.cacheHome.path, await _getExecutableName()),
);
if (legacyDirectory.existsSync()) {
return legacyDirectory.path;
}

await directory.create(recursive: true);
return directory.path;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/path_provider_linux/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: path_provider_linux
description: Linux implementation of the path_provider plugin
repository: https://github.com/flutter/packages/tree/main/packages/path_provider/path_provider_linux
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+path_provider%22
version: 2.2.1
version: 2.2.2

environment:
sdk: ^3.10.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider_linux/path_provider_linux.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:xdg_directories/xdg_directories.dart' as xdg;
Expand All @@ -10,6 +12,34 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
PathProviderLinux.registerWith();

// These tests use the actual filesystem, since an injectable filesystem
// would add a runtime dependency to the package, so everything is contained
// to a temporary directory.
late Directory testRoot;
final fakeEnv = <String, String>{};

setUp(() async {
testRoot = Directory.systemTemp.createTempSync();
fakeEnv['XDG_CACHE_HOME'] = p.join(
testRoot.path,
'application',
'cache',
'path',
);
fakeEnv['XDG_DATA_HOME'] = p.join(
testRoot.path,
'application',
'support',
'path',
);
xdg.xdgEnvironmentOverride = (String key) => fakeEnv[key];
});

tearDown(() {
fakeEnv.clear();
testRoot.deleteSync(recursive: true);
});

test('registered instance', () {
expect(PathProviderPlatform.instance, isA<PathProviderLinux>());
});
Expand Down Expand Up @@ -40,7 +70,6 @@ void main() {
executableName: 'path_provider_linux_test_binary',
applicationId: 'com.example.Test',
);
// Note this will fail if ${xdg.dataHome.path}/path_provider_linux_test_binary exists on the local filesystem.
expect(
await plugin.getApplicationSupportPath(),
'${xdg.dataHome.path}/com.example.Test',
Expand All @@ -60,6 +89,21 @@ void main() {
},
);

test(
'getApplicationSupportPath uses executable name fallback if subdir already exists',
() async {
final PathProviderPlatform plugin = PathProviderLinux.private(
executableName: 'path_provider_linux_test_binary',
applicationId: 'com.example.Test',
);
final executableNameDir = Directory(
p.join('${xdg.dataHome.path}', 'path_provider_linux_test_binary'),
);
await executableNameDir.create(recursive: true);
expect(await plugin.getApplicationSupportPath(), executableNameDir.path);
},
);

test('getApplicationDocumentsPath', () async {
final PathProviderPlatform plugin = PathProviderPlatform.instance;
expect(await plugin.getApplicationDocumentsPath(), startsWith('/'));
Expand All @@ -68,13 +112,42 @@ void main() {
test('getApplicationCachePath', () async {
final PathProviderPlatform plugin = PathProviderLinux.private(
executableName: 'path_provider_linux_test_binary',
applicationId: 'com.example.Test',
);
expect(
await plugin.getApplicationCachePath(),
'${xdg.cacheHome.path}/path_provider_linux_test_binary',
'${xdg.cacheHome.path}/com.example.Test',
);
});

test(
'getApplicationCachePath uses executable name if no application Id',
() async {
final PathProviderPlatform plugin = PathProviderLinux.private(
executableName: 'path_provider_linux_test_binary',
);
expect(
await plugin.getApplicationCachePath(),
'${xdg.cacheHome.path}/path_provider_linux_test_binary',
);
},
);

test(
'getApplicationCachePath uses executable name fallback if subdir already exists',
() async {
final PathProviderPlatform plugin = PathProviderLinux.private(
executableName: 'path_provider_linux_test_binary',
applicationId: 'com.example.Test',
);
final executableNameDir = Directory(
p.join('${xdg.cacheHome.path}', 'path_provider_linux_test_binary'),
);
await executableNameDir.create(recursive: true);
expect(await plugin.getApplicationCachePath(), executableNameDir.path);
},
);

test('getDownloadsPath', () async {
final PathProviderPlatform plugin = PathProviderPlatform.instance;
expect(await plugin.getDownloadsPath(), startsWith('/'));
Expand Down