Filesystem: Add length check for moveto

This commit is contained in:
Jonathan Jenne 2022-09-29 09:10:45 +02:00
parent 59cfbb1984
commit 072aef5f21

View File

@ -121,33 +121,6 @@ Public Class File
Dim oVersionSeparator As Char = "~"c
' Split Filename without extension at version separator to:
' - Check if file is already versioned
' - Get the file version of an already versioned file
'
' Example:
' test1.pdf --> test1 --> ['test1'] --> no fileversion
' test1~2.pdf --> test1~2 --> ['test1', '2'] --> version 2
' test1~12345~2.pdf --> test1~12345~2 --> ['test1', '12345', '2'] --> still version 2
'Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
'Dim oSplitFilename = oFileNameWithoutExtension.Split(oVersionSeparator).ToList()
' if file is already versioned, extract file version
' else just use the filename and set version to 1
'If oSplitFilename.Count > 1 Then
' Dim oVersion As Integer = 1
' Try
' oVersion = Integer.Parse(oSplitFilename.Last())
' oFileNameWithoutExtension = String.Join("", oSplitFilename.Take(oSplitFilename.Count - 1))
' Catch ex As Exception
' ' oFilenameWithoutExtension does NOT change
' oFileNameWithoutExtension = oFileNameWithoutExtension
' Finally
' oFileVersion = oVersion
' End Try
'Else
' oFileVersion = 1
'End If
Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
Dim oSplitResult = GetVersionedString(oFileNameWithoutExtension, oVersionSeparator)
@ -157,7 +130,8 @@ Public Class File
' Shorten the filename (only filename, without extension or version)
' by cutting the length in half. This should work no matter how long the path and/or filename are.
If oFileName.Length > MAX_FILE_PATH_LENGTH Then
' The initial check operates on the full path to catch all scenarios.
If Destination.Length > MAX_FILE_PATH_LENGTH Then
_Logger.Info("Filename is too long. Filename will be cut to prevent further errors.")
_Logger.Info("Original Filename is: {0}", oFileNameWithoutExtension)
Dim oNewLength As Integer = Math.Round(oFileNameWithoutExtension.Length / 2)