Refactor readPacmanConfig
Reduced indentation && increased readability
This commit is contained in:
parent
6892191275
commit
42fe907ec8
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user