Import error if directory name square brackets

Sonarr version (exact version): 3.0.9.1549
Mono version (if Sonarr is not running on Windows): Windows 11 22H2 (OS Build 22621.819)
OS: Windows 11
Debug logs:
Description of issue: I’m using qbittorrent. I’m able to import shows successfully, unless the directory name contains square brackets “[]”. If the path contains a square bracket, i.e. [rarbg] then I can not import and I get the following error message. I have confirmed that it is not a permissions issue, the service is running as Local System. I’ve narrowed it down to only directories that have square brackets.

2022-11-17 10:51:01.5|Warn|ImportApprovedEpisodes|Couldn't import episode D:\Media\Torrent Download Folder\The.Good.Doctor.S06E06.Hot.and.Bothered.1080p.AMZN.WEBRip.DDP5.1.x264-NTb[rarbg]\The.Good.Doctor.S06E06.Hot.and.Bothered.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb.mkv

[v3.0.9.1549] System.UnauthorizedAccessException: Access to the path is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.__Error.WinIOError()
   at System.IO.File.InternalMove(String sourceFileName, String destFileName, Boolean checkHost)
   at NzbDrone.Common.Disk.DiskProviderBase.MoveFileInternal(String source, String destination) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskProviderBase.cs:line 268
   at NzbDrone.Common.Disk.DiskProviderBase.MoveFile(String source, String destination, Boolean overwrite) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskProviderBase.cs:line 255
   at NzbDrone.Common.Disk.DiskTransferService.TryMoveFileVerified(String sourcePath, String targetPath, Int64 originalSize) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskTransferService.cs:line 487
   at NzbDrone.Common.Disk.DiskTransferService.TransferFile(String sourcePath, String targetPath, TransferMode mode, Boolean overwrite) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Common\Disk\DiskTransferService.cs:line 367
   at NzbDrone.Core.MediaFiles.EpisodeFileMovingService.TransferFile(EpisodeFile episodeFile, Series series, List`1 episodes, String destinationFilePath, TransferMode mode) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\EpisodeFileMovingService.cs:line 116
   at NzbDrone.Core.MediaFiles.EpisodeFileMovingService.MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\EpisodeFileMovingService.cs:line 77
   at NzbDrone.Core.MediaFiles.UpgradeMediaFileService.UpgradeEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode, Boolean copyOnly) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\UpgradeMediaFileService.cs:line 77
   at NzbDrone.Core.MediaFiles.EpisodeImport.ImportApprovedEpisodes.Import(List`1 decisions, Boolean newDownload, DownloadClientItem downloadClientItem, ImportMode importMode) in M:\BuildAgent\work\63739567f01dbcc2\src\NzbDrone.Core\MediaFiles\EpisodeImport\ImportApprovedEpisodes.cs:line 109

Is that the correct path on disk?

This looks a lot like this fix (which is in 3.0.9.1549):

But there have been several versions of Qbit that have been problematic, especially 4.4.x.
Which version of Qbit?

Thanks for the quick reply!

Yes that is the correct path on the disk.

I’m running Qbit v4.4.5 (64-bit).

What about the destination path? Debug logs will show that path which could be the cause of the issue (the error doesn’t specify one way or another).

Do you mean is the destination path valid? If so, yes it’s valid.

As a workaround I’ve updated my qbit post processing script. I pass in the torrent hash, then using the qbit API I rename it, removing the troublesome characters. It’s all working nicely now, Sonarr is able to import it again.

I might have jumped the gun with this :frowning: I’m sure when I tested it worked, but it’s failing now.

I’m sure it’s something to do with the “[” and “]” characters. This only happens to torrents that have those characters in their name, all others get imported without issue. Even when I manually rename them (by removing “[” and “]”) I still get the Access to the path is denied error message.

Hi @markus101, I think I’ve figured out what is going on after looking at the source code and also setting the logging level to debug/trace.

As expected it has nothing to do with the square bracket characters, what it turned out to be was if the torrent was completed, then it would try to move the file, but for some reason it fails when attempting a move.

I tested a move using powershell and running [System.IO.File]::MoveFile(), and it moves fine.

For torrents that are still seeding I see it uses a transfer mode of HardLinkOrCopy, and they all work fine, in fact for these problematic ones, I can force them back to seeding, and then after a short time Sonarr will import it (using mode HardLinkOrCopy).

I’ll keep digging into why the Move is failing - but if you have any ideas, please let me know.

Thanks.

Ok figured it out. I had done some testing with my own console app, I’d built it with TopShelf and set it to run as a service, all it did was do a System.IO.File.Move(), which worked. I thought I’d set it to run with the same credentials as the Sonarr service. But upon double-checking I see I had that set as Local System and Sonarr runs as Local Service.

It was pretty simple in the end, it was indeed a file permission issue. Local Service didn’t have the ability to delete the existing file (which I guess it needs to perform a Move operation). As soon as I added Local Service with Modify permissions to my torrent download folder, it all started working.