Skip to content
Merged
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
9 changes: 8 additions & 1 deletion lib/common/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,17 @@ class AppPath {
Future<String> getProvidersFilePath(
String id,
String type,
String providerName,
String url,
) async {
final directory = await profilesPath;
return join(directory, 'providers', id, type, url.toMd5());
return join(
directory,
'providers',
id,
type,
'${providerName.toMd5()}-${url.toMd5()}',
);
}

Future<String> get tempPath async {
Expand Down
10 changes: 8 additions & 2 deletions lib/common/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ Future<VM2<String, String>> _makeRealProfileTask(
final addedRules = data.addedRules;
final appendSystemDns = data.appendSystemDns;
final defaultUA = data.defaultUA;
String getProvidersFilePathInner(String type, String url) {
String getProvidersFilePathInner(
String type,
String providerName,
String url,
) {
return join(
profilesPath,
'providers',
profileId.toString(),
type,
url.toMd5(),
'${providerName.toMd5()}-${url.toMd5()}',
);
}

Expand Down Expand Up @@ -203,6 +207,7 @@ Future<VM2<String, String>> _makeRealProfileTask(
if (proxyProvider['url'] != null) {
proxyProvider['path'] = getProvidersFilePathInner(
'proxies',
key.toString(),
proxyProvider['url'],
);
}
Expand All @@ -218,6 +223,7 @@ Future<VM2<String, String>> _makeRealProfileTask(
if (ruleProvider['url'] != null) {
ruleProvider['path'] = getProvidersFilePathInner(
'rules',
key.toString(),
ruleProvider['url'],
);
}
Expand Down
54 changes: 53 additions & 1 deletion test/common/task_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:io';

import 'package:fl_clash/common/task.dart';
import 'package:fl_clash/common/common.dart';
import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/models/models.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -41,6 +41,58 @@ void main() {
expect(result['ip-version'], 'ipv6-prefer');
});

test(
'proxy providers with the same URL receive separate cache files',
() async {
const url = 'https://subscription.example/providers';
final rawConfig = <String, dynamic>{
'proxy-providers': {
'provider-one': {
'type': 'http',
'url': url,
'header': {
'Id': ['file-one'],
},
},
'provider-two': {
'type': 'http',
'url': url,
'header': {
'Id': ['file-two'],
},
},
},
};
final profile = await makeRealProfileTask(
MakeRealProfileState(
profilesPath: '/tmp/flclash-provider-cache-test',
profileId: 15,
rawConfig: rawConfig,
realPatchConfig: const PatchClashConfig(),
overrideDns: false,
appendSystemDns: false,
proxyGroups: const [],
rules: const [],
addedRules: const [],
defaultUA: 'FlClash-Test',
),
);

expect(
profile.a,
contains(
'providers/15/proxies/${'provider-one'.toMd5()}-${url.toMd5()}',
),
);
expect(
profile.a,
contains(
'providers/15/proxies/${'provider-two'.toMd5()}-${url.toMd5()}',
),
);
},
);

test('profile ipv6 false also wins over the client fallback', () {
final result = applyCorePatchConfig(
rawConfig: {'ipv6': false},
Expand Down
Loading