Merge pull request 'Use regex to filter databases' (#3) from feature/filterDatabasesForTransfer into dev

Reviewed-on: #3
This commit is contained in:
ProfessionalUwU 2023-06-18 18:59:19 +00:00 committed by Gitea
commit 60dfb368e6
Signed by: Gitea
GPG Key ID: FCACD432A6DD0FB5
2 changed files with 28 additions and 4 deletions

View File

@ -93,6 +93,24 @@ public class PacserverUtils {
}
}
public List<String> databasesToTransfer = new List<String>();
public void filterDiffOutputForDatabases() {
foreach (string database in diffOfPackagesOrDatabases) {
databasesToTransfer.Add(getDatabaseFromRegex(database, @"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/*db")); // https://regex101.com/r/Wm5M0P/1
}
}
public string getDatabaseFromRegex(string input, string pattern) {
string match = string.Empty;
MatchCollection matchCollection = Regex.Matches(input, pattern);
foreach (Match matches in matchCollection) {
match = matches.Value;
}
return match;
}
private static List<String> newerPackagesAndDatabases = new List<String>();
public async void transferPacmanCache() {
HttpClient client = new HttpClient();

View File

@ -6,7 +6,7 @@ public class Program {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Please specify an option.");
Console.ResetColor();
Console.WriteLine("Possible options are: determinePacmanCacheDirectory, packagesBefore, packagesAfter, diffPackages, databasesBefore, databasesAfter, diffDatabases");
Console.WriteLine("Possible options are: determinePacmanCacheDirectory, packagesBefore, packagesAfter, diffPackages, databasesBefore, databasesAfter, diffDatabases, filter");
return;
}
@ -27,7 +27,7 @@ public class Program {
break;
case "diffPackages":
utils.diff("/tmp/before_update.txt", "/tmp/after_update.txt");
string packages = string.Join(",", utils.diffOfPackagesOrDatabases);
string packages = string.Join("\n", utils.diffOfPackagesOrDatabases);
Console.WriteLine(packages);
break;
case "databasesBefore":
@ -40,14 +40,20 @@ public class Program {
break;
case "diffDatabases":
utils.diff("/tmp/databases_before.txt", "/tmp/databases_after.txt");
string databases = string.Join(",", utils.diffOfPackagesOrDatabases);
string databases = string.Join("\n", utils.diffOfPackagesOrDatabases);
Console.WriteLine(databases);
break;
case "filter":
utils.diff("/tmp/databases_before.txt", "/tmp/databases_after.txt");
utils.filterDiffOutputForDatabases();
string filteredDatabases = string.Join("\n", utils.databasesToTransfer);
Console.WriteLine(filteredDatabases);
break;
default:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(args[0] + " is not a recognized option.");
Console.ResetColor();
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
Console.WriteLine("Possible options are: determinePacmanCacheDirectory, packagesBefore, packagesAfter, diffPackages, databasesBefore, databasesAfter, diffDatabases, filter");
break;
}
}