Refactored out goto statement.

This commit is contained in:
Roger Far 2025-01-19 19:55:19 -07:00
parent 353b9ca07b
commit e449bd7928

View file

@ -59,6 +59,7 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
});
String? file = null;
var shouldSearch = true;
// When resolving symlinks for AllDebrid, we know the exact file path, so we can skip the search.
if (clientKind == Torrent.TorrentClientKind.AllDebrid)
@ -71,16 +72,24 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
{
_logger.Debug($"Found file {path} at {potentialFilePath} using direct search");
file = potentialFilePath;
goto skipFileSearch;
shouldSearch = false;
}
else
{
// Log if the file wasn't found and continue searching.
_logger.Warning($"Expected file {path} to be at {potentialFilePath} but it wasn't found. Continuing search (this will probably fail).");
}
}
var potentialFilePaths = new List<String> { searchPath };
if (shouldSearch)
{
var potentialFilePaths = new List<String>
{
searchPath
};
var directoryInfo = new DirectoryInfo(searchPath);
while (directoryInfo.Parent != null)
{
potentialFilePaths.Add(directoryInfo.Name);
@ -94,6 +103,7 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
potentialFilePaths.Add(fileName);
potentialFilePaths.Add(fileNameWithoutExtension);
// add an empty path so we can check for the new file in the base directory
potentialFilePaths.Add("");
@ -137,10 +147,12 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
break;
}
}
}
if (file == null)
{
_logger.Debug($"Unable to find file in rclone mount. Folders available in {rcloneMountPath}: ");
try
{
var allFolders = FileHelper.GetDirectoryContents(rcloneMountPath);
@ -155,9 +167,6 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
throw new("Could not find file from rclone mount!");
}
// Used by Alldebrid since we know the exact file path.
skipFileSearch:
_logger.Debug($"Creating symbolic link from {file} to {destinationPath}");
var result = TryCreateSymbolicLink(file, destinationPath);