Purging directory: System.IO.PathTooLongException

We’ve a minor issue where under certain circumstances our app creates a number of folders and files and the path becomes too long. On the subsequent deployment, it causes Octopus to fail to purge the folder when deploying a package:

09:15:46   Info     |       Purging the directory 'E:\WebApp'
09:16:26   Error    |       System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
09:16:26   Error    |       at System.IO.PathHelper.GetFullPathName()
09:16:26   Error    |       at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
09:16:26   Error    |       at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
09:16:26   Error    |       at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
09:16:26   Error    |       at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
09:16:26   Error    |       at System.IO.FileSystemInfo.get_FullName()
09:16:26   Error    |       at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 373
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options, CancellationToken cancel, Boolean includeTarget) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 403
09:16:26   Error    |       at Calamari.Integration.FileSystem.CalamariPhysicalFileSystem.PurgeDirectory(String targetDirectory, Predicate`1 exclude, FailureOptions options) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Integration\FileSystem\CalamariPhysicalFileSystem.cs:line 361
09:16:26   Error    |       at Calamari.Deployment.Conventions.CopyPackageToCustomInstallationDirectoryConvention.Install(RunningDeployment deployment) in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Deployment\Conventions\CopyPackageToCustomInstallationDirectoryConvention.cs:line 62
09:16:26   Error    |       at Calamari.Deployment.ConventionProcessor.RunInstallConventions() in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Deployment\ConventionProcessor.cs:line 60
09:16:26   Error    |       at Calamari.Deployment.ConventionProcessor.RunConventions() in Z:\buildAgent\workDir\14ffc968155e4956\source\Calamari\Deployment\ConventionProcessor.cs:line 28
09:16:26   Error    |       Running rollback conventions...

Workaround is to simply delete the contents of the folder manually and carry on.

Octopus Server version 3.11.4
Calamari version 3.7.5

Hello,

Thanks for getting in touch. Yes, long paths are not great to deal with, thanks for letting us know you encountered this, it helps us prioritize what issues to work on.

We have an issue in progress to fix this across the various sub-systems of Octopus. But it’s still a work in progress. I appreciate it’s not ideal but if you can just keep going with your manual work around for now.

If you like you can follow along with the progress of the 2 related issues here: https://github.com/OctopusDeploy/Issues/issues/3129 and https://github.com/OctopusDeploy/Issues/issues/2532

Thanks &
Regards,
Nick

Thanks Nick for the quick response, I’ll look out for a fix in a future version.

Like I mentioned, just a minor issue for us that crops up from time to time, but can confuse (or panic) an inexperienced deployer so it would be good to see a resolution.

Thanks again.