99using System . Reflection . PortableExecutable ;
1010using System . Text . RegularExpressions ;
1111using Coverlet . Core . Abstracts ;
12- using Coverlet . Core . Logging ;
1312
1413namespace Coverlet . Core . Helpers
1514{
@@ -73,7 +72,7 @@ public string[] GetCoverableModules(string module, string[] directories, bool in
7372 public bool HasPdb ( string module , out bool embedded )
7473 {
7574 embedded = false ;
76- using ( var moduleStream = File . OpenRead ( module ) )
75+ using ( var moduleStream = _fileSystem . OpenRead ( module ) )
7776 using ( var peReader = new PEReader ( moduleStream ) )
7877 {
7978 foreach ( var entry in peReader . ReadDebugDirectory ( ) )
@@ -88,7 +87,7 @@ public bool HasPdb(string module, out bool embedded)
8887 return true ;
8988 }
9089
91- return File . Exists ( codeViewData . Path ) ;
90+ return _fileSystem . Exists ( codeViewData . Path ) ;
9291 }
9392 }
9493
@@ -99,7 +98,7 @@ public bool HasPdb(string module, out bool embedded)
9998 public bool EmbeddedPortablePdbHasLocalSource ( string module , out string firstNotFoundDocument )
10099 {
101100 firstNotFoundDocument = "" ;
102- using ( FileStream moduleStream = File . OpenRead ( module ) )
101+ using ( Stream moduleStream = _fileSystem . OpenRead ( module ) )
103102 using ( var peReader = new PEReader ( moduleStream ) )
104103 {
105104 foreach ( DebugDirectoryEntry entry in peReader . ReadDebugDirectory ( ) )
@@ -117,7 +116,7 @@ public bool EmbeddedPortablePdbHasLocalSource(string module, out string firstNot
117116 // We verify all docs and return false if not all are present in local
118117 // We could have false negative if doc is not a source
119118 // Btw check for all possible extension could be weak approach
120- if ( ! File . Exists ( docName ) )
119+ if ( ! _fileSystem . Exists ( docName ) )
121120 {
122121 firstNotFoundDocument = docName ;
123122 return false ;
@@ -136,15 +135,15 @@ public bool EmbeddedPortablePdbHasLocalSource(string module, out string firstNot
136135 public bool PortablePdbHasLocalSource ( string module , out string firstNotFoundDocument )
137136 {
138137 firstNotFoundDocument = "" ;
139- using ( var moduleStream = File . OpenRead ( module ) )
138+ using ( var moduleStream = _fileSystem . OpenRead ( module ) )
140139 using ( var peReader = new PEReader ( moduleStream ) )
141140 {
142141 foreach ( var entry in peReader . ReadDebugDirectory ( ) )
143142 {
144143 if ( entry . Type == DebugDirectoryEntryType . CodeView )
145144 {
146145 var codeViewData = peReader . ReadCodeViewDebugDirectoryData ( entry ) ;
147- using FileStream pdbStream = new FileStream ( codeViewData . Path , FileMode . Open ) ;
146+ using Stream pdbStream = _fileSystem . NewFileStream ( codeViewData . Path , FileMode . Open ) ;
148147 using MetadataReaderProvider metadataReaderProvider = MetadataReaderProvider . FromPortablePdbStream ( pdbStream ) ;
149148 MetadataReader metadataReader = null ;
150149 try
@@ -182,16 +181,16 @@ public void BackupOriginalModule(string module, string identifier)
182181 {
183182 var backupPath = GetBackupPath ( module , identifier ) ;
184183 var backupSymbolPath = Path . ChangeExtension ( backupPath , ".pdb" ) ;
185- File . Copy ( module , backupPath , true ) ;
184+ _fileSystem . Copy ( module , backupPath , true ) ;
186185 if ( ! _backupList . TryAdd ( module , backupPath ) )
187186 {
188187 throw new ArgumentException ( $ "Key already added '{ module } '") ;
189188 }
190189
191190 var symbolFile = Path . ChangeExtension ( module , ".pdb" ) ;
192- if ( File . Exists ( symbolFile ) )
191+ if ( _fileSystem . Exists ( symbolFile ) )
193192 {
194- File . Copy ( symbolFile , backupSymbolPath , true ) ;
193+ _fileSystem . Copy ( symbolFile , backupSymbolPath , true ) ;
195194 if ( ! _backupList . TryAdd ( symbolFile , backupSymbolPath ) )
196195 {
197196 throw new ArgumentException ( $ "Key already added '{ module } '") ;
@@ -210,18 +209,18 @@ public void RestoreOriginalModule(string module, string identifier)
210209
211210 _retryHelper . Retry ( ( ) =>
212211 {
213- File . Copy ( backupPath , module , true ) ;
214- File . Delete ( backupPath ) ;
212+ _fileSystem . Copy ( backupPath , module , true ) ;
213+ _fileSystem . Delete ( backupPath ) ;
215214 _backupList . TryRemove ( module , out string _ ) ;
216215 } , retryStrategy , 10 ) ;
217216
218217 _retryHelper . Retry ( ( ) =>
219218 {
220- if ( File . Exists ( backupSymbolPath ) )
219+ if ( _fileSystem . Exists ( backupSymbolPath ) )
221220 {
222221 string symbolFile = Path . ChangeExtension ( module , ".pdb" ) ;
223- File . Copy ( backupSymbolPath , symbolFile , true ) ;
224- File . Delete ( backupSymbolPath ) ;
222+ _fileSystem . Copy ( backupSymbolPath , symbolFile , true ) ;
223+ _fileSystem . Delete ( backupSymbolPath ) ;
225224 _backupList . TryRemove ( symbolFile , out string _ ) ;
226225 }
227226 } , retryStrategy , 10 ) ;
@@ -238,8 +237,8 @@ public void RestoreOriginalModules()
238237 string backupPath = _backupList [ key ] ;
239238 _retryHelper . Retry ( ( ) =>
240239 {
241- File . Copy ( backupPath , key , true ) ;
242- File . Delete ( backupPath ) ;
240+ _fileSystem . Copy ( backupPath , key , true ) ;
241+ _fileSystem . Delete ( backupPath ) ;
243242 _backupList . TryRemove ( key , out string _ ) ;
244243 } , retryStrategy , 10 ) ;
245244 }
@@ -250,7 +249,7 @@ public void DeleteHitsFile(string path)
250249 // Retry hitting the hits file - retry up to 10 times, since the file could be locked
251250 // See: https://github.com/tonerdo/coverlet/issues/25
252251 var retryStrategy = CreateRetryStrategy ( ) ;
253- _retryHelper . Retry ( ( ) => File . Delete ( path ) , retryStrategy , 10 ) ;
252+ _retryHelper . Retry ( ( ) => _fileSystem . Delete ( path ) , retryStrategy , 10 ) ;
254253 }
255254
256255 public bool IsValidFilterExpression ( string filter )
0 commit comments