Due to those trailing path separators an issue occurs when the the path is passed as directoryToClean to the RecursiveDeleteEmptyDirectories function. The function iterates over all directories in toBeChecked up to directoryToClean and adds any valid paths to directoriesToClean.
The behaviour can be seen in the following debug window:
The function was given ["C:\\shoko\\import\\tsukimichi"] as toBeChecked and "C:\\shoko\\import\\" as directoryToClean. Which obviously results in an exception when it reaches that ternary operator on the 2nd iteration of the while loop.
Simply removing those trailing path separators from directoryToClean fixes this issue on my end.
SVR_ImportFolder.ImportFolderLocation
has a trailingPath.DirectorySeparatorChar
like seen here https://github.com/ShokoAnime/ShokoServer/blob/5b016cbce43e0c60bee05138f08671051a3e182b/Shoko.Server/Models/SVR_ImportFolder.cs#L33Due to those trailing path separators an issue occurs when the the path is passed as
directoryToClean
to theRecursiveDeleteEmptyDirectories
function. The function iterates over all directories intoBeChecked
up todirectoryToClean
and adds any valid paths todirectoriesToClean
.So when the function reaches a
path
equal todirectoryToClean
it should stop iterating over that tree. The issue is that thepath
returned by https://github.com/ShokoAnime/ShokoServer/blob/5b016cbce43e0c60bee05138f08671051a3e182b/Shoko.Server/Services/VideoLocal_PlaceService.cs#L497 does not have any trailing path separators. Resulting in the equality check here to be false, even though the two paths are technically equal https://github.com/ShokoAnime/ShokoServer/blob/5b016cbce43e0c60bee05138f08671051a3e182b/Shoko.Server/Services/VideoLocal_PlaceService.cs#L491 This results in aArgumentOutOfRangeException
from the substring it is trying to build due todirectoriesToClean
being longer with its trailing path separators.The behaviour can be seen in the following debug window: The function was given
["C:\\shoko\\import\\tsukimichi"]
astoBeChecked
and"C:\\shoko\\import\\"
asdirectoryToClean
. Which obviously results in an exception when it reaches that ternary operator on the 2nd iteration of the while loop.Simply removing those trailing path separators from
directoryToClean
fixes this issue on my end.