@@ -32,6 +32,7 @@ public sealed class DependencyManager : IDisposable
3232 private readonly FileContent fileContent ;
3333 private readonly TemporaryDirectory packageDirectory ;
3434 private readonly TemporaryDirectory tempWorkingDirectory ;
35+ private readonly bool cleanupTempWorkingDirectory ;
3536
3637 /// <summary>
3738 /// Performs C# dependency fetching.
@@ -59,7 +60,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
5960 this . progressMonitor . FindingFiles ( srcDir ) ;
6061
6162 packageDirectory = new TemporaryDirectory ( ComputeTempDirectory ( sourceDir . FullName ) ) ;
62- tempWorkingDirectory = new TemporaryDirectory ( GetTemporaryWorkingDirectory ( ) ) ;
63+ tempWorkingDirectory = new TemporaryDirectory ( GetTemporaryWorkingDirectory ( out cleanupTempWorkingDirectory ) ) ;
6364
6465 var allFiles = GetAllFiles ( ) ;
6566 var binaryFileExtensions = new HashSet < string > ( new [ ] { ".dll" , ".exe" } ) ; // TODO: add more binary file extensions.
@@ -285,15 +286,17 @@ private static string ComputeTempDirectory(string srcDir)
285286 return Path . Combine ( Path . GetTempPath ( ) , "GitHub" , "packages" , sb . ToString ( ) ) ;
286287 }
287288
288- private static string GetTemporaryWorkingDirectory ( )
289+ private static string GetTemporaryWorkingDirectory ( out bool cleanupTempWorkingDirectory )
289290 {
291+ cleanupTempWorkingDirectory = false ;
290292 var tempFolder = EnvironmentVariables . GetScratchDirectory ( ) ;
291293
292294 if ( string . IsNullOrEmpty ( tempFolder ) )
293295 {
294296 var tempPath = Path . GetTempPath ( ) ;
295297 var name = Guid . NewGuid ( ) . ToString ( "N" ) . ToUpper ( ) ;
296298 tempFolder = Path . Combine ( tempPath , "GitHub" , name ) ;
299+ cleanupTempWorkingDirectory = true ;
297300 }
298301
299302 return tempFolder ;
@@ -574,7 +577,8 @@ private void AnalyseSolutions(IEnumerable<string> solutions)
574577 public void Dispose ( )
575578 {
576579 packageDirectory ? . Dispose ( ) ;
577- tempWorkingDirectory ? . Dispose ( ) ;
580+ if ( cleanupTempWorkingDirectory )
581+ tempWorkingDirectory ? . Dispose ( ) ;
578582 }
579583 }
580584}
0 commit comments