Compare commits
3 Commits
60dfb368e6
...
dc811d7462
Author | SHA1 | Date | |
---|---|---|---|
dc811d7462 | |||
07982425e0 | |||
e609caf892 |
@ -22,8 +22,8 @@ public class checkForNewerStuffTest {
|
|||||||
utils.readPacmanConfig();
|
utils.readPacmanConfig();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
utils.getEveryPackageNameAndVersionViaFolderName("/tmp/before_update.txt");
|
utils.getEveryPackageNameAndVersion("before", "/tmp/packages_before.txt");
|
||||||
utils.getEveryPackageNameAndVersionViaFolderName("/tmp/after_update.txt");
|
utils.getEveryPackageNameAndVersion("after", "/tmp/packages_after.txt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
File.Exists("/tmp/before_update.txt").Should().BeTrue();
|
File.Exists("/tmp/before_update.txt").Should().BeTrue();
|
||||||
@ -35,7 +35,7 @@ public class checkForNewerStuffTest {
|
|||||||
// Arrange
|
// Arrange
|
||||||
PacserverUtils utils = new PacserverUtils();
|
PacserverUtils utils = new PacserverUtils();
|
||||||
utils.readPacmanConfig();
|
utils.readPacmanConfig();
|
||||||
utils.getEveryPackageNameAndVersionViaFolderName("/tmp/before_update.txt");
|
utils.getEveryPackageNameAndVersion("before", "/tmp/packages_before.txt");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
List<String> packageList = utils.packageNamesAndVersion;
|
List<String> packageList = utils.packageNamesAndVersion;
|
||||||
@ -52,7 +52,7 @@ public class checkForNewerStuffTest {
|
|||||||
utils.pacmanDatabaseDirectory = "/tmp/";
|
utils.pacmanDatabaseDirectory = "/tmp/";
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Action act = () => utils.getEveryPackageNameAndVersionViaFolderName("/tmp/before_update.txt");
|
Action act = () => utils.getEveryPackageNameAndVersion("before", "/tmp/packages_before.txt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
act.Should().Throw<Exception>().WithMessage("How did you execute this without any packages?");
|
act.Should().Throw<Exception>().WithMessage("How did you execute this without any packages?");
|
||||||
|
@ -37,16 +37,49 @@ public class PacserverUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> packageNamesAndVersion = new List<String>();
|
public List<String> packageNamesAndVersion = new List<String>();
|
||||||
public void getEveryPackageNameAndVersionViaFolderName(string filePath) {
|
public void getEveryPackageNameAndVersion(string mode, string filePath) {
|
||||||
string[] directories = Directory.GetDirectories(pacmanDatabaseDirectory + "local/");
|
Regex regex = new Regex(@".+\.pkg\.tar\.zst$");
|
||||||
foreach (string directory in directories) {
|
|
||||||
packageNamesAndVersion.Add(new DirectoryInfo(directory).Name);
|
if (Directory.Exists(pacmanCacheDirectory)) {
|
||||||
|
if (Directory.GetFiles(pacmanCacheDirectory) is not null) {
|
||||||
|
packageNamesAndVersion = Directory.GetFiles(pacmanCacheDirectory).Where(file => regex.IsMatch(file)).ToList();
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("No packages found in pacman cache");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("No pacman cache directory found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageNamesAndVersion.Capacity > 0) {
|
switch (mode) {
|
||||||
File.WriteAllLines(filePath, packageNamesAndVersion);
|
case "before":
|
||||||
} else {
|
writePackageNamesAndVersionToFile(filePath);
|
||||||
throw new Exception("How did you execute this without any packages?");
|
break;
|
||||||
|
case "after":
|
||||||
|
writePackageNamesAndVersionToFile(filePath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("No valid mode was given. Valid modes are before and after");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePackageNamesAndVersionToFile(string filePath) {
|
||||||
|
if (!File.Exists(filePath)) {
|
||||||
|
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
||||||
|
using (StreamWriter sw = new StreamWriter(filePath)) {
|
||||||
|
foreach (string package in packageNamesAndVersion) {
|
||||||
|
sw.WriteLine(package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (File.Exists(filePath)) {
|
||||||
|
File.Delete(filePath);
|
||||||
|
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
||||||
|
using (var sw = new StreamWriter(filePath)) {
|
||||||
|
foreach (string package in packageNamesAndVersion) {
|
||||||
|
sw.WriteLine(package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +118,9 @@ public class PacserverUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (File.Exists(filePath)) {
|
} else if (File.Exists(filePath)) {
|
||||||
using (File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
File.Delete(filePath);
|
||||||
using (var sw = new StreamWriter(filePath, true)) {
|
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
||||||
|
using (var sw = new StreamWriter(filePath)) {
|
||||||
sw.WriteLine(database + " " + File.GetLastAccessTime(database));
|
sw.WriteLine(database + " " + File.GetLastAccessTime(database));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ public class Program {
|
|||||||
break;
|
break;
|
||||||
case "packagesBefore":
|
case "packagesBefore":
|
||||||
utils.readPacmanConfig();
|
utils.readPacmanConfig();
|
||||||
utils.getEveryPackageNameAndVersionViaFolderName("/tmp/before_update.txt");
|
utils.getEveryPackageNameAndVersion("before", "/tmp/packages_before.txt");
|
||||||
break;
|
break;
|
||||||
case "packagesAfter":
|
case "packagesAfter":
|
||||||
utils.readPacmanConfig();
|
utils.readPacmanConfig();
|
||||||
utils.getEveryPackageNameAndVersionViaFolderName("/tmp/after_update.txt");
|
utils.getEveryPackageNameAndVersion("after", "/tmp/packages_after.txt");
|
||||||
break;
|
break;
|
||||||
case "diffPackages":
|
case "diffPackages":
|
||||||
utils.diff("/tmp/before_update.txt", "/tmp/after_update.txt");
|
utils.diff("/tmp/packages_before.txt", "/tmp/packages_after.txt");
|
||||||
string packages = string.Join("\n", utils.diffOfPackagesOrDatabases);
|
string packages = string.Join("\n", utils.diffOfPackagesOrDatabases);
|
||||||
Console.WriteLine(packages);
|
Console.WriteLine(packages);
|
||||||
break;
|
break;
|
||||||
@ -49,6 +49,12 @@ public class Program {
|
|||||||
string filteredDatabases = string.Join("\n", utils.databasesToTransfer);
|
string filteredDatabases = string.Join("\n", utils.databasesToTransfer);
|
||||||
Console.WriteLine(filteredDatabases);
|
Console.WriteLine(filteredDatabases);
|
||||||
break;
|
break;
|
||||||
|
case "getEveryPackageInCache":
|
||||||
|
utils.readPacmanConfig();
|
||||||
|
utils.getEveryPackageNameAndVersion("before", "/tmp/packages_before.txt");
|
||||||
|
string allPackages = string.Join("\n", utils.packageNamesAndVersion);
|
||||||
|
Console.WriteLine(allPackages);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine(args[0] + " is not a recognized option.");
|
Console.WriteLine(args[0] + " is not a recognized option.");
|
||||||
|
Loading…
Reference in New Issue
Block a user