Skip to content

Commit

Permalink
Fixed FileNotFoundException during backup when there is a symlink in …
Browse files Browse the repository at this point in the history
…data folder
  • Loading branch information
Bounz committed Jun 24, 2018
1 parent bbfaa9e commit 6ff9aa7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion HomeGenie/Utils/ArchiveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal static void AddFolderToZip(string zipFilename, string folderPath)

using (var archive = ZipArchive.Create())
{
archive.AddAllFromDirectory(folderPath);
archive.SafeAddAllFromDirectory(folderPath);
archive.SaveTo(zipFilename, CompressionType.Deflate);
}
}
Expand All @@ -94,5 +94,25 @@ internal static void AddFolderToZip(string zipFilename, string folderPath)
throw;
}
}

private static void SafeAddAllFromDirectory(
this IWritableArchive writableArchive,
string filePath, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories)
{
foreach (var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption))
{
// On Unix we can get FileNotFoundException when getting FileInfo on symlink
try
{
var fileInfo = new FileInfo(path);
writableArchive.AddEntry(path.Substring(filePath.Length), fileInfo.OpenRead(), true, fileInfo.Length,
fileInfo.LastWriteTime);
}
catch (Exception e)
{
Log.Warn("Can't access file at " + path, e);
}
}
}
}
}

0 comments on commit 6ff9aa7

Please sign in to comment.