Fix edgecases, improve reliability
This commit is contained in:
parent
83285d244c
commit
b2e35ba301
|
@ -349,3 +349,5 @@ healthchecksdb
|
||||||
MigrationBackup/
|
MigrationBackup/
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
repomgr
|
||||||
|
|
64
RepoMgr.cs
64
RepoMgr.cs
|
@ -76,23 +76,16 @@ namespace repomgr
|
||||||
UpdatePackage(package);
|
UpdatePackage(package);
|
||||||
if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()"))
|
if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()"))
|
||||||
Shell.Exec("makepkg -os --noconfirm", Path.Combine(_pkgpath, package.Name));
|
Shell.Exec("makepkg -os --noconfirm", Path.Combine(_pkgpath, package.Name));
|
||||||
package.CurrentVersion =
|
package.CurrentVersion = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name));
|
||||||
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];
|
|
||||||
WriteIndex();
|
WriteIndex();
|
||||||
if (package.CurrentVersion != package.RepoVersion || force)
|
if (force)
|
||||||
Shell.Exec("makepkg -csf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
|
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;
|
else return;
|
||||||
|
|
||||||
var resultingPackages = Directory
|
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)
|
if (resultingPackages.Length < 1)
|
||||||
{
|
{
|
||||||
package.LastBuildSucceeded = false;
|
package.LastBuildSucceeded = false;
|
||||||
|
@ -100,16 +93,26 @@ namespace repomgr
|
||||||
}
|
}
|
||||||
|
|
||||||
package.LastBuildSucceeded = true;
|
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")))
|
foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig")))
|
||||||
{
|
{
|
||||||
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
|
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
|
||||||
File.Delete(resultingPackage);
|
File.Delete(resultingPackage);
|
||||||
|
package.PkgFiles.Add(Path.GetFileName(resultingPackage));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig")))
|
foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig")))
|
||||||
{
|
{
|
||||||
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
|
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
|
||||||
File.Delete(resultingPackage);
|
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);
|
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;
|
package.RepoVersion = package.CurrentVersion;
|
||||||
|
@ -121,15 +124,20 @@ namespace repomgr
|
||||||
if (Directory.Exists(packageDir))
|
if (Directory.Exists(packageDir))
|
||||||
Directory.Delete(packageDir, true);
|
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);
|
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*"))
|
if (package.PkgFiles.Any())
|
||||||
File.Delete(file);
|
{
|
||||||
|
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);
|
_repo.Packages.Remove(package);
|
||||||
WriteIndex();
|
WriteIndex();
|
||||||
}
|
}
|
||||||
public void List()
|
public void List()
|
||||||
{
|
{
|
||||||
Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):"));
|
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)}";
|
var line = $"{Shell.Bold(package.Name)}";
|
||||||
if (package.RepoVersion != package.CurrentVersion)
|
if (package.RepoVersion != package.CurrentVersion)
|
||||||
|
@ -265,6 +273,7 @@ namespace repomgr
|
||||||
public string CurrentVersion = "never-updated";
|
public string CurrentVersion = "never-updated";
|
||||||
public string RepoVersion = "nA";
|
public string RepoVersion = "nA";
|
||||||
public bool LastBuildSucceeded = true;
|
public bool LastBuildSucceeded = true;
|
||||||
|
public readonly List<string> PkgFiles = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class Shell
|
internal static class Shell
|
||||||
|
@ -289,6 +298,29 @@ namespace repomgr
|
||||||
process.Start();
|
process.Start();
|
||||||
process.WaitForExit();
|
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)
|
public static string Bold(string s)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
|
<Configurations>Debug;Release</Configurations>
|
||||||
|
<Platforms>AnyCPU</Platforms>
|
||||||
|
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ Global
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
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.ActiveCfg = Release|Any CPU
|
||||||
{86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
Loading…
Reference in New Issue