diff --git a/Filesystem/File.vb b/Filesystem/File.vb index c8823aca..3b04c95a 100644 --- a/Filesystem/File.vb +++ b/Filesystem/File.vb @@ -39,6 +39,9 @@ Public Class File ' Source: https://docs.microsoft.com/de-de/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#maximum-path-length-limitation Private Const MAX_FILE_PATH_LENGTH = 250 + ' This prevents an infinite loop when no file can be created in a location + Private Const MAX_FILE_VERSION = 100 + Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt" Public Sub New(LogConfig As LogConfig) @@ -151,8 +154,13 @@ Public Class File oFileNameWithoutExtension = oNewFileNameWithoutExtension End If - ' while file exists, increment version + ' while file exists, increment version. + ' version cannot go above MAX_FILE_VERSION, to prevent infinite loop Do + If oFileVersion >= MAX_FILE_VERSION Then + Throw New OverflowException($"Tried '{MAX_FILE_VERSION}' times to version filename before giving up. Sorry.") + End If + oFinalFileName = Path.Combine(oDestinationDir, GetFilenameWithVersion(oFileNameWithoutExtension, oVersionSeparator, oFileVersion, oExtension)) _Logger.Debug("Intermediate Filename is {0}", oFinalFileName) _Logger.Debug("File version: {0}", oFileVersion)