From 15ccf8130a16a93d06e29521d3c90fbc6b11771a Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Sat, 2 Apr 2022 20:28:09 +0200 Subject: Ignore exception when file access time is not valid When getting the value from FileSystemInfo.LastAccessTime, it will internally convert the FILETIME value from Windows API to a DateTime. If the value represents a date after 12/31/9999 it will throw ArgumentOutOfRangeException, because this is not supported by DateTime. Some file systems seem to set strange access timestamps on files, which may lead to this exception being thrown. Since the last accessed timestamp is not important such exceptions are now just silently ignored. --- Duplicati/Library/Common/IO/SystemIOWindows.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Duplicati/Library/Common/IO/SystemIOWindows.cs b/Duplicati/Library/Common/IO/SystemIOWindows.cs index adf797d2a..343dcb78e 100644 --- a/Duplicati/Library/Common/IO/SystemIOWindows.cs +++ b/Duplicati/Library/Common/IO/SystemIOWindows.cs @@ -508,7 +508,19 @@ namespace Duplicati.Library.Common.IO public IFileEntry FileEntry(string path) { var fileInfo = new FileInfo(AddExtendedDevicePathPrefix(path)); - return new FileEntry(fileInfo.Name, fileInfo.Length, fileInfo.LastAccessTime, fileInfo.LastWriteTime); + var lastAccess = new DateTime(); + try + { + // Internally this will convert the FILETIME value from Windows API to a + // DateTime. If the value represents a date after 12/31/9999 it will throw + // ArgumentOutOfRangeException, because this is not supported by DateTime. + // Some file systems seem to set strange access timestamps on files, which + // may lead to this exception being thrown. Since the last accessed + // timestamp is not important such exeptions are just silently ignored. + lastAccess = fileInfo.LastAccessTime; + } + catch { } + return new FileEntry(fileInfo.Name, fileInfo.Length, lastAccess, fileInfo.LastWriteTime); } public Dictionary GetMetadata(string path, bool isSymlink, bool followSymlink) -- cgit v1.2.3