@@ -32,6 +32,7 @@ public sealed class DependencyManager : IDisposable
32
32
private readonly FileContent fileContent ;
33
33
private readonly TemporaryDirectory packageDirectory ;
34
34
private readonly TemporaryDirectory tempWorkingDirectory ;
35
+ private readonly bool cleanupTempWorkingDirectory ;
35
36
36
37
/// <summary>
37
38
/// Performs C# dependency fetching.
@@ -59,7 +60,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
59
60
this . progressMonitor . FindingFiles ( srcDir ) ;
60
61
61
62
packageDirectory = new TemporaryDirectory ( ComputeTempDirectory ( sourceDir . FullName ) ) ;
62
- tempWorkingDirectory = new TemporaryDirectory ( GetTemporaryWorkingDirectory ( ) ) ;
63
+ tempWorkingDirectory = new TemporaryDirectory ( GetTemporaryWorkingDirectory ( out cleanupTempWorkingDirectory ) ) ;
63
64
64
65
var allFiles = GetAllFiles ( ) ;
65
66
var binaryFileExtensions = new HashSet < string > ( new [ ] { ".dll" , ".exe" } ) ; // TODO: add more binary file extensions.
@@ -285,15 +286,17 @@ private static string ComputeTempDirectory(string srcDir)
285
286
return Path . Combine ( Path . GetTempPath ( ) , "GitHub" , "packages" , sb . ToString ( ) ) ;
286
287
}
287
288
288
- private static string GetTemporaryWorkingDirectory ( )
289
+ private static string GetTemporaryWorkingDirectory ( out bool cleanupTempWorkingDirectory )
289
290
{
291
+ cleanupTempWorkingDirectory = false ;
290
292
var tempFolder = EnvironmentVariables . GetScratchDirectory ( ) ;
291
293
292
294
if ( string . IsNullOrEmpty ( tempFolder ) )
293
295
{
294
296
var tempPath = Path . GetTempPath ( ) ;
295
297
var name = Guid . NewGuid ( ) . ToString ( "N" ) . ToUpper ( ) ;
296
298
tempFolder = Path . Combine ( tempPath , "GitHub" , name ) ;
299
+ cleanupTempWorkingDirectory = true ;
297
300
}
298
301
299
302
return tempFolder ;
@@ -574,7 +577,8 @@ private void AnalyseSolutions(IEnumerable<string> solutions)
574
577
public void Dispose ( )
575
578
{
576
579
packageDirectory ? . Dispose ( ) ;
577
- tempWorkingDirectory ? . Dispose ( ) ;
580
+ if ( cleanupTempWorkingDirectory )
581
+ tempWorkingDirectory ? . Dispose ( ) ;
578
582
}
579
583
}
580
584
}
0 commit comments