Refactor readPacmanConfig

Reduced indentation && increased readability
This commit is contained in:
AustrianToast 2023-06-21 21:35:20 +02:00
parent 6892191275
commit 42fe907ec8
No known key found for this signature in database
GPG Key ID: 5CD422268E489EB4
2 changed files with 13 additions and 14 deletions

View File

@ -4,7 +4,7 @@ namespace Pacserver.Tests;
public class TranserFilesTest {
[Fact]
public void transferPacmanCache_doesNotFail() {
public async void transferPacmanCache_doesNotFail() {
// Arrange
PacserverUtils utils = new PacserverUtils();

View File

@ -33,23 +33,22 @@ public partial class PacserverUtils {
string? line;
while ((line = file.ReadLine()) is not null) {
foreach (string path in pathsToDetermine.Where(path => line.Contains(path))) {
string cachePath = pathsToDetermine[0];
string dbPath = pathsToDetermine[1];
if (line.Contains(cachePath) || line.Contains(dbPath)) {
Match match = CacheDirOrDBPathRegex().Match(line);
if (match.Success) {
switch (path) {
case "CacheDir":
pacmanCacheDirectory = match.ToString();
break;
case "DBPath":
pacmanDatabaseDirectory = match.ToString();
break;
default:
throw new ArgumentException("Could not deal with " + match.ToString());
}
} else {
if(!match.Success) {
string pathsToDetermineString = string.Join(",", pathsToDetermine);
throw new DirectoryNotFoundException("Could not determine the necessary file paths: " + pathsToDetermineString);
}
if (line.Contains(cachePath)) {
pacmanCacheDirectory = match.ToString();
} else if (line.Contains(dbPath)) {
pacmanDatabaseDirectory = match.ToString();
}
}
}
}