Refactored out goto statement.
This commit is contained in:
parent
353b9ca07b
commit
e449bd7928
1 changed files with 75 additions and 66 deletions
|
|
@ -59,6 +59,7 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
|
||||||
});
|
});
|
||||||
|
|
||||||
String? file = null;
|
String? file = null;
|
||||||
|
var shouldSearch = true;
|
||||||
|
|
||||||
// When resolving symlinks for AllDebrid, we know the exact file path, so we can skip the search.
|
// When resolving symlinks for AllDebrid, we know the exact file path, so we can skip the search.
|
||||||
if (clientKind == Torrent.TorrentClientKind.AllDebrid)
|
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");
|
_logger.Debug($"Found file {path} at {potentialFilePath} using direct search");
|
||||||
file = potentialFilePath;
|
file = potentialFilePath;
|
||||||
goto skipFileSearch;
|
shouldSearch = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Log if the file wasn't found and continue searching.
|
// 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).");
|
_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);
|
var directoryInfo = new DirectoryInfo(searchPath);
|
||||||
|
|
||||||
while (directoryInfo.Parent != null)
|
while (directoryInfo.Parent != null)
|
||||||
{
|
{
|
||||||
potentialFilePaths.Add(directoryInfo.Name);
|
potentialFilePaths.Add(directoryInfo.Name);
|
||||||
|
|
@ -94,6 +103,7 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
|
||||||
|
|
||||||
potentialFilePaths.Add(fileName);
|
potentialFilePaths.Add(fileName);
|
||||||
potentialFilePaths.Add(fileNameWithoutExtension);
|
potentialFilePaths.Add(fileNameWithoutExtension);
|
||||||
|
|
||||||
// add an empty path so we can check for the new file in the base directory
|
// add an empty path so we can check for the new file in the base directory
|
||||||
potentialFilePaths.Add("");
|
potentialFilePaths.Add("");
|
||||||
|
|
||||||
|
|
@ -137,10 +147,12 @@ public class SymlinkDownloader(String uri, String destinationPath, String path,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (file == null)
|
if (file == null)
|
||||||
{
|
{
|
||||||
_logger.Debug($"Unable to find file in rclone mount. Folders available in {rcloneMountPath}: ");
|
_logger.Debug($"Unable to find file in rclone mount. Folders available in {rcloneMountPath}: ");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var allFolders = FileHelper.GetDirectoryContents(rcloneMountPath);
|
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!");
|
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}");
|
_logger.Debug($"Creating symbolic link from {file} to {destinationPath}");
|
||||||
|
|
||||||
var result = TryCreateSymbolicLink(file, destinationPath);
|
var result = TryCreateSymbolicLink(file, destinationPath);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue