Compare commits
25 Commits
main
...
a03dffabb7
Author | SHA1 | Date | |
---|---|---|---|
a03dffabb7
|
|||
405b3580b6
|
|||
013bc2fe33
|
|||
a9ac6d8bc2
|
|||
88c6d7c284
|
|||
7bbeaedf48 | |||
332ed62ca3 | |||
205ef71dcd | |||
a61c3fbfd9
|
|||
3d512f25ab
|
|||
4f474591da
|
|||
81fc8f1883
|
|||
89e79b1025
|
|||
35c6c5c8d9
|
|||
9ad8012052
|
|||
10ba654b09
|
|||
888df20cc9
|
|||
04048c4cb9
|
|||
20599a03ba
|
|||
5a09db7423
|
|||
281b6f01a2
|
|||
64100065c9
|
|||
d4dc405b2b
|
|||
22ffc338e7
|
|||
00b50f0601
|
26
.editorconfig
Normal file
26
.editorconfig
Normal file
@ -0,0 +1,26 @@
|
||||
# Remove the line below if you want to inherit .editorconfig settings from higher directories
|
||||
root = true
|
||||
|
||||
# C# files
|
||||
[*.cs]
|
||||
|
||||
# Indentation and spacing
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
tab_width = 4
|
||||
|
||||
# Naming Conventions
|
||||
dotnet_naming_style.camel_case.capitalization = camel_case
|
||||
|
||||
# New line preferences
|
||||
csharp_new_line_before_open_brace = none
|
||||
csharp_new_line_before_else = false
|
||||
csharp_new_line_before_catch = false
|
||||
csharp_new_line_before_finally = false
|
||||
|
||||
# Wrapping preferences
|
||||
csharp_preserve_single_line_statements = true
|
||||
csharp_preserve_single_line_blocks = true
|
||||
|
||||
# Switch case
|
||||
csharp_indent_case_contents = true
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.vscode/
|
||||
[Oo]bj/
|
||||
[Bb]in/
|
31
justfile
Normal file
31
justfile
Normal file
@ -0,0 +1,31 @@
|
||||
default:
|
||||
@just --list
|
||||
|
||||
project_name := `printf '%s\n' "${PWD##*/}"`
|
||||
uppercase_project_name := capitalize(project_name)
|
||||
|
||||
setup:
|
||||
@dotnet new sln --name {{project_name}}
|
||||
@mkdir src
|
||||
@dotnet new classlib -o src/{{uppercase_project_name}}
|
||||
@dotnet new xunit -o src/{{uppercase_project_name}}.Tests
|
||||
@dotnet sln add src/{{uppercase_project_name}}/{{uppercase_project_name}}.csproj
|
||||
@dotnet sln add src/{{uppercase_project_name}}.Tests/{{uppercase_project_name}}.Tests.csproj
|
||||
@dotnet add src/{{uppercase_project_name}}/{{uppercase_project_name}}.csproj reference src/{{uppercase_project_name}}.Tests/{{uppercase_project_name}}.Tests.csproj
|
||||
|
||||
run:
|
||||
@dotnet run
|
||||
|
||||
build:
|
||||
@dotnet build src/{{uppercase_project_name}}/{{project_name}}.csproj
|
||||
@dotnet build src/{{uppercase_project_name}}.Tests/{{uppercase_project_name}}.Tests.csproj
|
||||
|
||||
publish: format
|
||||
@dotnet publish --configuration Release src/{{uppercase_project_name}}/{{project_name}}.csproj
|
||||
|
||||
format:
|
||||
@dotnet format src/{{uppercase_project_name}}
|
||||
@dotnet format src/{{uppercase_project_name}}.Tests
|
||||
|
||||
test: build
|
||||
@dotnet test src/{{uppercase_project_name}}.Tests
|
28
src/Pacserver.Tests/Pacserver.Tests.csproj
Normal file
28
src/Pacserver.Tests/Pacserver.Tests.csproj
Normal file
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pacserver\pacserver.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
18
src/Pacserver.Tests/TransferFilesTest.cs
Normal file
18
src/Pacserver.Tests/TransferFilesTest.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
namespace Pacserver.Tests;
|
||||
|
||||
public class TranserFilesTest {
|
||||
[Fact]
|
||||
public void transferPacmanCache_doesNotFail() {
|
||||
// Arrange
|
||||
PacserverUtils utils = new PacserverUtils();
|
||||
|
||||
// Act
|
||||
utils.readPacmanConfig();
|
||||
utils.transferPacmanCache();
|
||||
|
||||
// Assert
|
||||
//Assert.NotEmpty(Directory.GetFiles("/home/rene/test/"));
|
||||
}
|
||||
}
|
1
src/Pacserver.Tests/Usings.cs
Normal file
1
src/Pacserver.Tests/Usings.cs
Normal file
@ -0,0 +1 @@
|
||||
global using Xunit;
|
18
src/Pacserver.Tests/readPacmanConfigTest.cs
Normal file
18
src/Pacserver.Tests/readPacmanConfigTest.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
namespace Pacserver.Tests;
|
||||
|
||||
public class readPacmanConfigTest {
|
||||
[Fact]
|
||||
public void readPacmanConfig_returnsNoException() {
|
||||
// Arrange
|
||||
PacserverUtils utils = new PacserverUtils();
|
||||
|
||||
// Act
|
||||
var exception = Record.Exception(() => utils.readPacmanConfig());
|
||||
|
||||
// Assert
|
||||
Assert.Null(exception);
|
||||
}
|
||||
}
|
||||
|
60
src/Pacserver/Pacserver.cs
Normal file
60
src/Pacserver/Pacserver.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Pacserver.Utils;
|
||||
public class PacserverUtils {
|
||||
public string pacmanCacheDirectory { get; set; } = string.Empty;
|
||||
public static string pacmanDatabaseDirectory { get; set; } = string.Empty;
|
||||
public static List<String> pathsToDetermine = new List<String>() { "CacheDir", "DBPath" };
|
||||
public void readPacmanConfig() {
|
||||
using (StreamReader file = new StreamReader("/etc/pacman.conf")) {
|
||||
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
|
||||
string? line;
|
||||
|
||||
while ((line = file.ReadLine()) is not null) {
|
||||
foreach (string path in pathsToDetermine) {
|
||||
if (line.Contains(path)) {
|
||||
Match match = regex.Match(line);
|
||||
if (match.Success) {
|
||||
switch (path) {
|
||||
case "CacheDir":
|
||||
pacmanCacheDirectory = match.ToString();
|
||||
break;
|
||||
case "DBPath":
|
||||
pacmanDatabaseDirectory = match.ToString();
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Could not deal with " + match.ToString());
|
||||
}
|
||||
} else {
|
||||
string pathsToDetermineString = string.Join(",", pathsToDetermine);
|
||||
throw new Exception("Could not determine the necessary file paths: " + pathsToDetermineString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForNewerPackagesAndDatabases() {
|
||||
|
||||
}
|
||||
|
||||
private static List<String> newerPackagesAndDatabases = new List<String>();
|
||||
public async void transferPacmanCache() {
|
||||
HttpClient client = new HttpClient();
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://192.168.0.69:12000/upload?path=/");
|
||||
MultipartFormDataContent content = new MultipartFormDataContent();
|
||||
|
||||
foreach (string pkgOrDb in newerPackagesAndDatabases) {
|
||||
content.Add(new ByteArrayContent(File.ReadAllBytes(pacmanCacheDirectory + pkgOrDb)), "path", Path.GetFileName(pacmanCacheDirectory + pkgOrDb));
|
||||
}
|
||||
request.Content = content;
|
||||
|
||||
await client.SendAsync(request);
|
||||
}
|
||||
|
||||
public void transferPacmanDatabases() {
|
||||
|
||||
}
|
||||
}
|
27
src/Pacserver/Program.cs
Normal file
27
src/Pacserver/Program.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
public class Program {
|
||||
static void Main(string[] args) {
|
||||
if (args.Length == 0) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Please specify an option.");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "determinePacmanCacheDirectory":
|
||||
PacserverUtils utils = new PacserverUtils();
|
||||
utils.readPacmanConfig();
|
||||
Console.WriteLine(utils.pacmanCacheDirectory);
|
||||
break;
|
||||
default:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(args[0] + " is not a recognized option.");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
14
src/Pacserver/pacserver.csproj
Normal file
14
src/Pacserver/pacserver.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<SelfContained>true</SelfContained>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
32
src/pacserver.sln
Normal file
32
src/pacserver.sln
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pacserver", "Pacserver\pacserver.csproj", "{2B605458-AFBE-4A78-B4EA-9562C82BC932}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pacserver.Tests", "Pacserver.Tests\Pacserver.Tests.csproj", "{0B504958-E66D-4E32-AB22-19F94713AFCD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Reference in New Issue
Block a user