#1 fix by using copy strategy overwrite on change

This commit is contained in:
ErXBout 2021-10-31 16:06:14 +01:00
parent 5b4c51eca0
commit f6e900f292

View file

@ -43,8 +43,27 @@ namespace SynologyCertificateExporter.Services
var cpFrom = _synoDirectory + "/" + certificate.Name + "/" + fileName;
var cpTo = exportDirectory + "/" + fileName;
Console.WriteLine($"Copy file from {cpFrom} to {cpTo}");
File.Copy(cpFrom, cpTo);
if (File.Exists(cpTo))
{
var cpFromFileInfo = new FileInfo(cpFrom);
var cpToFileInfo = new FileInfo(cpTo);
if (cpFromFileInfo.CreationTime != cpToFileInfo.CreationTime)
{
Console.WriteLine($"Copy file from {cpFrom} to {cpTo} with overwrite because creationtime changed");
File.Copy(cpFrom, cpTo, true);
}
else
{
Console.WriteLine($"Skipping copy from {cpFrom} to {cpTo}");
}
}
else
{
Console.WriteLine($"Copy file from {cpFrom} to {cpTo}");
File.Copy(cpFrom, cpTo);
}
}
}
}