Removed unused code && Added extra logic to check if things exist

This commit is contained in:
FUH22860 2023-01-12 22:38:29 +01:00
parent 21b61759d6
commit 378c907146
2 changed files with 27 additions and 51 deletions

View File

@ -5,5 +5,7 @@
string result2 = Update.copyEverthingFromBackupLocationToFinalDestination(); string result2 = Update.copyEverthingFromBackupLocationToFinalDestination();
Console.WriteLine(result2); Console.WriteLine(result2);
Console.WriteLine(args);
} }
} }

View File

@ -1,5 +1,3 @@
using System.Diagnostics;
using System.IO;
public class Update { public class Update {
public static string getHomePath() { public static string getHomePath() {
string homePath = string.Empty; string homePath = string.Empty;
@ -38,59 +36,35 @@ public class Update {
return $"Copied {copiedFiles} to {targetPath}"; return $"Copied {copiedFiles} to {targetPath}";
} }
/// <summary>
/// Method <c>copyEverthingFromBackupLocationToFinalDestination</c> copies everything to second Backup Location which should be a external drive or a network share. Offsite/Second Backup.
/// </summary>
public static string copyEverthingFromBackupLocationToFinalDestination() { public static string copyEverthingFromBackupLocationToFinalDestination() {
string targetPath = "/artemis/test/"; string targetPath = "/artemis/test/";
string sourcePath = getHomePath() + "/backup/";
string[] intermediateBackupLocation = Directory.GetFiles(sourcePath);
if (!Directory.Exists(targetPath)) { if (!Directory.Exists(targetPath)) {
throw new DirectoryNotFoundException("Target directory not found"); Console.ForegroundColor = ConsoleColor.Red;
} else { return $"Backup location does not exist! Please specify one in the config.";
foreach (string file in intermediateBackupLocation) { }
FileInfo info = new FileInfo(file);
string destFile = Path.Combine(targetPath, info.Name); if (targetPath is not null) {
File.Copy(info.FullName, destFile, true); string sourcePath = getHomePath() + "/backup/";
} string[] intermediateBackupLocation = Directory.GetFiles(sourcePath);
if (!Directory.Exists(targetPath)) {
throw new DirectoryNotFoundException("Target directory not found");
} else {
foreach (string file in intermediateBackupLocation) {
FileInfo info = new FileInfo(file);
string destFile = Path.Combine(targetPath, info.Name);
File.Copy(info.FullName, destFile, true);
}
}
Console.ForegroundColor = ConsoleColor.Green;
return $"Copied everything successfully to {targetPath}";
} else {
Console.ForegroundColor = ConsoleColor.Red;
return "You have not configured a backup location!";
} }
return $"Copied everything successfully to {targetPath}";
} }
// Commented code below was written by ChatGPT
// using System;
// using System.Diagnostics;
// namespace UpdateLinux
// {
// class Program
// {
// static void Main(string[] args)
// {
// Console.WriteLine("Updating Linux system...");
// // Use the Process class to run the "apt-get update" command
// var process = new Process()
// {
// StartInfo = new ProcessStartInfo
// {
// FileName = "yay",
// UseShellExecute = false,
// RedirectStandardOutput = true,
// RedirectStandardError = true
// }
// };
// process.Start();
// // Read the output of the "apt-get update" command
// string output = process.StandardOutput.ReadToEnd();
// string error = process.StandardError.ReadToEnd();
// process.WaitForExit();
// Console.WriteLine(output);
// Console.WriteLine(error);
// Console.WriteLine("Linux system updated!");
// }
// }
// }
} }