Compare commits
5 Commits
dc811d7462
...
dev
Author | SHA1 | Date | |
---|---|---|---|
15220e7135
|
|||
590b06fc86
|
|||
65b15f657d | |||
82a854dd8b | |||
5018856aab |
@ -7,9 +7,11 @@ public class checkForNewerStuffTest {
|
|||||||
public void checkForNewerPackages_throwsExceptionIfNoFilesExist() {
|
public void checkForNewerPackages_throwsExceptionIfNoFilesExist() {
|
||||||
// Arrange
|
// Arrange
|
||||||
PacserverUtils utils = new PacserverUtils();
|
PacserverUtils utils = new PacserverUtils();
|
||||||
|
File.Delete("/tmp/packages_before.txt");
|
||||||
|
File.Delete("/tmp/packages_after.txt");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Action act = () => utils.diff("/tmp/before_update.txt", "/tmp/after_update.txt");
|
Action act = () => utils.diff("/tmp/packages_before.txt", "/tmp/packages_after.txt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
act.Should().Throw<FileNotFoundException>().WithMessage("Necessary files could not be found");
|
act.Should().Throw<FileNotFoundException>().WithMessage("Necessary files could not be found");
|
||||||
@ -26,8 +28,8 @@ public class checkForNewerStuffTest {
|
|||||||
utils.getEveryPackageNameAndVersion("after", "/tmp/packages_after.txt");
|
utils.getEveryPackageNameAndVersion("after", "/tmp/packages_after.txt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
File.Exists("/tmp/before_update.txt").Should().BeTrue();
|
File.Exists("/tmp/packages_before.txt").Should().BeTrue();
|
||||||
File.Exists("/tmp/after_update.txt").Should().BeTrue();
|
File.Exists("/tmp/packages_before.txt").Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -45,16 +47,14 @@ public class checkForNewerStuffTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void getEveryPackageNameAndVersionViaFolderName_throwsExceptionIfListIsEmpty() {
|
public void getEveryPackageNameAndVersionViaFolderName_throwsExceptionIfModeIsNotValid() {
|
||||||
// Arrange
|
// Arrange
|
||||||
PacserverUtils utils = new PacserverUtils();
|
PacserverUtils utils = new PacserverUtils();
|
||||||
Directory.CreateDirectory("/tmp/local");
|
|
||||||
utils.pacmanDatabaseDirectory = "/tmp/";
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Action act = () => utils.getEveryPackageNameAndVersion("before", "/tmp/packages_before.txt");
|
Action act = () => utils.getEveryPackageNameAndVersion("test", "/tmp/test.txt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
act.Should().Throw<Exception>().WithMessage("How did you execute this without any packages?");
|
act.Should().Throw<ArgumentException>().WithMessage("No valid mode was given. Valid modes are before and after");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -63,7 +63,10 @@ public class PacserverUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writePackageNamesAndVersionToFile(string filePath) {
|
public void writePackageNamesAndVersionToFile(string filePath) {
|
||||||
if (!File.Exists(filePath)) {
|
if (File.Exists(filePath)) {
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
||||||
using (StreamWriter sw = new StreamWriter(filePath)) {
|
using (StreamWriter sw = new StreamWriter(filePath)) {
|
||||||
foreach (string package in packageNamesAndVersion) {
|
foreach (string package in packageNamesAndVersion) {
|
||||||
@ -71,16 +74,6 @@ public class PacserverUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> diffOfPackagesOrDatabases = new List<String>();
|
public List<String> diffOfPackagesOrDatabases = new List<String>();
|
||||||
@ -111,40 +104,24 @@ public class PacserverUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeDatabaseAccessTimeToFile(string filePath, string database) {
|
public void writeDatabaseAccessTimeToFile(string filePath, string database) {
|
||||||
if (!File.Exists(filePath)) {
|
if (File.Exists(filePath)) {
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
||||||
using (StreamWriter sw = new StreamWriter(filePath)) {
|
using (StreamWriter sw = new StreamWriter(filePath)) {
|
||||||
sw.WriteLine(database + " " + File.GetLastAccessTime(database));
|
sw.WriteLine(database + " " + File.GetLastAccessTime(database));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (File.Exists(filePath)) {
|
|
||||||
File.Delete(filePath);
|
|
||||||
using (File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) {
|
|
||||||
using (var sw = new StreamWriter(filePath)) {
|
|
||||||
sw.WriteLine(database + " " + File.GetLastAccessTime(database));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> databasesToTransfer = new List<String>();
|
public List<String> databasesToTransfer = new List<String>();
|
||||||
public void filterDiffOutputForDatabases() {
|
public void filterDiffOutputForDatabases() {
|
||||||
foreach (string database in diffOfPackagesOrDatabases) {
|
foreach (string database in diffOfPackagesOrDatabases) {
|
||||||
databasesToTransfer.Add(getDatabaseFromRegex(database, @"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/*db")); // https://regex101.com/r/Wm5M0P/1
|
databasesToTransfer.Add(Regex.Match(database, @"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/*db").Value); // https://regex101.com/r/Wm5M0P/1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getDatabaseFromRegex(string input, string pattern) {
|
|
||||||
string match = string.Empty;
|
|
||||||
MatchCollection matchCollection = Regex.Matches(input, pattern);
|
|
||||||
|
|
||||||
foreach (Match matches in matchCollection) {
|
|
||||||
match = matches.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<String> newerPackagesAndDatabases = new List<String>();
|
private static List<String> newerPackagesAndDatabases = new List<String>();
|
||||||
public async void transferPacmanCache() {
|
public async void transferPacmanCache() {
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
|
Reference in New Issue
Block a user