diff --git a/src/Pacserver.Tests/checkForNewerStuffTest.cs b/src/Pacserver.Tests/checkForNewerStuffTest.cs index 07b0f63..01685b1 100644 --- a/src/Pacserver.Tests/checkForNewerStuffTest.cs +++ b/src/Pacserver.Tests/checkForNewerStuffTest.cs @@ -21,7 +21,8 @@ public class checkForNewerStuffTest { public void getEveryPackageNameAndVersionViaFolderName_createsFiles() { // Arrange PacserverUtils utils = new PacserverUtils(); - utils.readPacmanConfig(); + Directory.CreateDirectory("/tmp/pacserverTest/"); + utils.pacmanCacheDirectory = "/tmp/pacserverTest/"; // Act utils.getEveryPackageNameAndVersion("before", utils.pacserverDirectory + "packages_before.txt"); @@ -33,17 +34,18 @@ public class checkForNewerStuffTest { } [Fact] - public void packageNamesAndVersion_notEmpty() { + public void packageNamesAndVersion_isEmpty() { // Arrange PacserverUtils utils = new PacserverUtils(); - utils.readPacmanConfig(); + Directory.CreateDirectory("/tmp/pacserverTest/"); + utils.pacmanCacheDirectory = "/tmp/pacserverTest/"; utils.getEveryPackageNameAndVersion("before", utils.pacserverDirectory + "packages_before.txt"); // Act - List packageList = utils.packageNamesAndVersion; + var packageList = utils.packageNamesAndVersion; // Assert - packageList.Should().NotBeNullOrEmpty(); + packageList.Should().BeEmpty(); } [Fact] diff --git a/src/Pacserver.Tests/getEverySigFileTest.cs b/src/Pacserver.Tests/getEverySigFileTest.cs new file mode 100644 index 0000000..4026637 --- /dev/null +++ b/src/Pacserver.Tests/getEverySigFileTest.cs @@ -0,0 +1,22 @@ +using Pacserver.Utils; + +namespace Pacserver.Tests; + +public class getEverySigFileTest { + [Fact] + public void getEverySigFile_ListShouldNotBeEmpty() { + // Arrange + PacserverUtils utils = new PacserverUtils(); + Directory.CreateDirectory("/tmp/pacserverTest/"); + utils.pacmanCacheDirectory = "/tmp/pacserverTest/"; + File.Create(utils.pacmanCacheDirectory + "zsh-5.9-3-x86_64.pkg.tar.zst.sig"); + + // Act + utils.getEverySigFile(); + var sigFiles = utils.sigFiles; + Directory.Delete(utils.pacmanCacheDirectory, true); + + // Assert + sigFiles.Should().NotBeEmpty(); + } +} \ No newline at end of file diff --git a/src/Pacserver/Pacserver.cs b/src/Pacserver/Pacserver.cs index 1ed2f5d..707253e 100644 --- a/src/Pacserver/Pacserver.cs +++ b/src/Pacserver/Pacserver.cs @@ -39,14 +39,14 @@ public partial class PacserverUtils { if (!line.Contains(cachePath) && !line.Contains(dbPath)) { continue; } - + Match match = CacheDirOrDBPathRegex().Match(line); - if(!match.Success) { + 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)) { @@ -96,6 +96,17 @@ public partial class PacserverUtils { } } + public List sigFiles = new List(); + [GeneratedRegex(@".+\.pkg\.tar\.zst\.sig$", RegexOptions.NonBacktracking)] + private static partial Regex onlyGetSigFiles(); + public void getEverySigFile() { + if (Directory.Exists(pacmanCacheDirectory)) { + if (Directory.GetFiles(pacmanCacheDirectory) is not null) { + sigFiles = Directory.GetFiles(pacmanCacheDirectory).Where(file => onlyGetSigFiles().IsMatch(file)).ToList(); + } + } + } + public List diffOfPackagesOrDatabases = new List(); public void diff(string before, string after) { if (File.Exists(before) && File.Exists(after)) { @@ -168,6 +179,7 @@ public partial class PacserverUtils { public void combinePackagesWithDatabases() { newerPackagesAndDatabases.AddRange(packageNamesAndVersion); newerPackagesAndDatabases.AddRange(databasesToTransfer); + newerPackagesAndDatabases.AddRange(sigFiles); } public async Task transfer() { diff --git a/src/Pacserver/Program.cs b/src/Pacserver/Program.cs index cd43e8b..a0a97bc 100644 --- a/src/Pacserver/Program.cs +++ b/src/Pacserver/Program.cs @@ -35,6 +35,7 @@ public class Program { utils.packageNamesAndVersion = utils.readDiffFileToList(utils.pacserverDirectory + "package_diff.txt"); + utils.getEverySigFile(); utils.combinePackagesWithDatabases(); utils.transfer();