Implement determinePacmanCacheDirectory
Used a StreamReader to read pacman.conf and then read one line until a line contains CacheDir Then used a regex to only get the cache directory
This commit is contained in:
parent
20599a03ba
commit
04048c4cb9
@ -6,7 +6,8 @@
|
||||
Console.ResetColor();
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case "":
|
||||
case "determinePacmanCacheDirectory":
|
||||
Pacserver.determinePacmanCacheDirectory();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
17
pacserver.cs
17
pacserver.cs
@ -1,6 +1,23 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class Pacserver {
|
||||
public static string pacmanCacheDirectory { get; set; } = string.Empty;
|
||||
public static string determinePacmanCacheDirectory() {
|
||||
// string defaultPacmanCacheDirectory = "/var/cache/pacman/pkg/";
|
||||
|
||||
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
|
||||
string? line;
|
||||
StreamReader file = new StreamReader(@"/etc/pacman.conf");
|
||||
while ((line = file.ReadLine()) is not null) {
|
||||
if (line.Contains("CacheDir")) {
|
||||
Match match = regex.Match(line);
|
||||
if (match.Success) {
|
||||
pacmanCacheDirectory = match.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
file.Close();
|
||||
|
||||
return pacmanCacheDirectory;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user