Fix edgecases, improve reliability
This commit is contained in:
parent
83285d244c
commit
b2e35ba301
|
@ -349,3 +349,5 @@ healthchecksdb
|
|||
MigrationBackup/
|
||||
|
||||
.idea/
|
||||
|
||||
repomgr
|
||||
|
|
64
RepoMgr.cs
64
RepoMgr.cs
|
@ -76,23 +76,16 @@ namespace repomgr
|
|||
UpdatePackage(package);
|
||||
if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()"))
|
||||
Shell.Exec("makepkg -os --noconfirm", Path.Combine(_pkgpath, package.Name));
|
||||
package.CurrentVersion =
|
||||
File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD"))
|
||||
.Split("\n")
|
||||
.First(p => p.StartsWith("pkgver="))
|
||||
.Split("pkgver=")[1];
|
||||
package.CurrentVersion += "-" +
|
||||
File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD"))
|
||||
.Split("\n")
|
||||
.First(p => p.StartsWith("pkgrel="))
|
||||
.Split("pkgrel=")[1];
|
||||
package.CurrentVersion = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name));
|
||||
WriteIndex();
|
||||
if (package.CurrentVersion != package.RepoVersion || force)
|
||||
Shell.Exec("makepkg -csf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
|
||||
if (force)
|
||||
Shell.Exec("makepkg -Ccsf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
|
||||
else if (package.CurrentVersion != package.RepoVersion)
|
||||
Shell.Exec("makepkg -Ccs --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
|
||||
else return;
|
||||
|
||||
var resultingPackages = Directory
|
||||
.GetFiles(Path.Combine(_pkgpath, package.Name), $"{package.Name}*{package.CurrentVersion}*.tar*");
|
||||
.GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*");
|
||||
if (resultingPackages.Length < 1)
|
||||
{
|
||||
package.LastBuildSucceeded = false;
|
||||
|
@ -100,16 +93,26 @@ namespace repomgr
|
|||
}
|
||||
|
||||
package.LastBuildSucceeded = true;
|
||||
if (package.PkgFiles.Any())
|
||||
{
|
||||
foreach (var pkgFile in package.PkgFiles)
|
||||
if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
|
||||
File.Delete(Path.Combine(_repo.Path, pkgFile));
|
||||
package.PkgFiles.Clear();
|
||||
}
|
||||
|
||||
foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig")))
|
||||
{
|
||||
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
|
||||
File.Delete(resultingPackage);
|
||||
package.PkgFiles.Add(Path.GetFileName(resultingPackage));
|
||||
}
|
||||
|
||||
foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig")))
|
||||
{
|
||||
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
|
||||
File.Delete(resultingPackage);
|
||||
package.PkgFiles.Add(Path.GetFileName(resultingPackage));
|
||||
Shell.Exec($"repo-add --remove --sign {_repo.Name}.db.tar.gz {Path.GetFileName(resultingPackage)} 2>&1| tee -a {Path.Combine(_buildpath, "repolog.txt")}", _repo.Path);
|
||||
}
|
||||
package.RepoVersion = package.CurrentVersion;
|
||||
|
@ -121,15 +124,20 @@ namespace repomgr
|
|||
if (Directory.Exists(packageDir))
|
||||
Directory.Delete(packageDir, true);
|
||||
Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name} 2>&1| tee -a {Path.Combine(_buildpath, "repolog.txt")}", _repo.Path);
|
||||
foreach (var file in Directory.GetFiles(_repo.Path, $"{package.Name}*.tar*"))
|
||||
File.Delete(file);
|
||||
if (package.PkgFiles.Any())
|
||||
{
|
||||
foreach (var pkgFile in package.PkgFiles)
|
||||
if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
|
||||
File.Delete(Path.Combine(_repo.Path, pkgFile));
|
||||
package.PkgFiles.Clear();
|
||||
}
|
||||
_repo.Packages.Remove(package);
|
||||
WriteIndex();
|
||||
}
|
||||
public void List()
|
||||
{
|
||||
Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):"));
|
||||
foreach (var package in _repo.Packages)
|
||||
foreach (var package in _repo.Packages.OrderBy(p => p.Name))
|
||||
{
|
||||
var line = $"{Shell.Bold(package.Name)}";
|
||||
if (package.RepoVersion != package.CurrentVersion)
|
||||
|
@ -265,6 +273,7 @@ namespace repomgr
|
|||
public string CurrentVersion = "never-updated";
|
||||
public string RepoVersion = "nA";
|
||||
public bool LastBuildSucceeded = true;
|
||||
public readonly List<string> PkgFiles = new List<string>();
|
||||
}
|
||||
|
||||
internal static class Shell
|
||||
|
@ -290,6 +299,29 @@ namespace repomgr
|
|||
process.WaitForExit();
|
||||
}
|
||||
|
||||
public static string ExecR(string cmd, string workingDirectory)
|
||||
{
|
||||
var escapedArgs = cmd.Replace("\"", "\\\"");
|
||||
|
||||
var process = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "/bin/bash",
|
||||
Arguments = $"-c \"{escapedArgs}\"",
|
||||
WorkingDirectory = workingDirectory,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
var stdout = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
return stdout.Trim();
|
||||
}
|
||||
|
||||
public static string Bold(string s)
|
||||
{
|
||||
return $"\x1B[1m{s}\x1B[21m";
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<DebugType>full</DebugType>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ Global
|
|||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Loading…
Reference in New Issue