@@ -94,6 +94,9 @@ private static void SetupDefaultClassification(Mock<IFileSystemInspector> inspec
9494 FileInfo => FileSystemEntryKind . RegularFile ,
9595 _ => FileSystemEntryKind . Unknown
9696 } ) ;
97+ inspector
98+ . Setup ( i => i . IsNoiseDirectoryName ( It . IsAny < DirectoryInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) )
99+ . Returns ( false ) ;
97100 }
98101
99102 [ Test ]
@@ -265,7 +268,72 @@ public async Task Noise_Child_File_Is_Recorded()
265268 await builder . BuildBaseInventoryAsync ( invPath ) ;
266269
267270 processData . SkippedEntries . Should ( )
268- . ContainSingle ( e => e . Name == "thumbs.db" && e . Reason == SkipReason . NoiseFile ) ;
271+ . ContainSingle ( e => e . Name == "thumbs.db" && e . Reason == SkipReason . NoiseEntry ) ;
272+ }
273+
274+ [ Test ]
275+ public async Task Noise_Child_Directory_Is_Recorded_And_Not_Traversed ( )
276+ {
277+ var insp = new Mock < IFileSystemInspector > ( MockBehavior . Strict ) ;
278+ SetupDefaultClassification ( insp ) ;
279+ insp . Setup ( i => i . IsHidden ( It . IsAny < DirectoryInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) ) . Returns ( false ) ;
280+ insp . Setup ( i => i . IsHidden ( It . IsAny < FileInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) ) . Returns ( false ) ;
281+ insp . Setup ( i => i . IsNoiseDirectoryName ( It . Is < DirectoryInfo > ( di => di . Name == "$RECYCLE.BIN" ) , It . IsAny < OSPlatforms > ( ) ) )
282+ . Returns ( true ) ;
283+ insp . Setup ( i => i . IsNoiseFileName ( It . IsAny < FileInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) ) . Returns ( false ) ;
284+ insp . Setup ( i => i . IsSystemAttribute ( It . IsAny < FileInfo > ( ) ) ) . Returns ( false ) ;
285+ insp . Setup ( i => i . IsReparsePoint ( It . IsAny < FileSystemInfo > ( ) ) ) . Returns ( false ) ;
286+ insp . Setup ( i => i . Exists ( It . IsAny < FileInfo > ( ) ) ) . Returns ( true ) ;
287+ insp . Setup ( i => i . IsOffline ( It . IsAny < FileInfo > ( ) ) ) . Returns ( false ) ;
288+ insp . Setup ( i => i . IsRecallOnDataAccess ( It . IsAny < FileInfo > ( ) ) ) . Returns ( false ) ;
289+ var ( builder , processData ) = CreateBuilderWithData ( insp . Object ) ;
290+
291+ var root = Directory . CreateDirectory ( Path . Combine ( TestDirectory . FullName , "root_noise_dir" ) ) ;
292+ var visiblePath = Path . Combine ( root . FullName , "visible.txt" ) ;
293+ await File . WriteAllTextAsync ( visiblePath , "x" ) ;
294+
295+ var noiseDirectory = Directory . CreateDirectory ( Path . Combine ( root . FullName , "$RECYCLE.BIN" ) ) ;
296+ var nestedNoiseFile = Path . Combine ( noiseDirectory . FullName , "nested.txt" ) ;
297+ await File . WriteAllTextAsync ( nestedNoiseFile , "x" ) ;
298+
299+ builder . AddInventoryPart ( root . FullName ) ;
300+ var invPath = Path . Combine ( TestDirectory . FullName , "inv_noise_dir.zip" ) ;
301+ await builder . BuildBaseInventoryAsync ( invPath ) ;
302+
303+ var part = builder . Inventory . InventoryParts . Single ( ) ;
304+ part . FileDescriptions . Should ( ) . ContainSingle ( fd => fd . Name == "visible.txt" ) ;
305+ part . FileDescriptions . Should ( ) . NotContain ( fd => fd . Name == "nested.txt" ) ;
306+
307+ processData . SkippedEntries . Should ( )
308+ . ContainSingle ( e => e . Name == "$RECYCLE.BIN" && e . Reason == SkipReason . NoiseEntry ) ;
309+ }
310+
311+ [ Test ]
312+ public async Task Noise_Root_Directory_Is_Analyzed ( )
313+ {
314+ var insp = new Mock < IFileSystemInspector > ( MockBehavior . Strict ) ;
315+ SetupDefaultClassification ( insp ) ;
316+ insp . Setup ( i => i . IsHidden ( It . IsAny < DirectoryInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) ) . Returns ( false ) ;
317+ insp . Setup ( i => i . IsHidden ( It . IsAny < FileInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) ) . Returns ( false ) ;
318+ insp . Setup ( i => i . IsNoiseFileName ( It . IsAny < FileInfo > ( ) , It . IsAny < OSPlatforms > ( ) ) ) . Returns ( false ) ;
319+ insp . Setup ( i => i . IsSystemAttribute ( It . IsAny < FileInfo > ( ) ) ) . Returns ( false ) ;
320+ insp . Setup ( i => i . IsReparsePoint ( It . IsAny < FileSystemInfo > ( ) ) ) . Returns ( false ) ;
321+ insp . Setup ( i => i . Exists ( It . IsAny < FileInfo > ( ) ) ) . Returns ( true ) ;
322+ insp . Setup ( i => i . IsOffline ( It . IsAny < FileInfo > ( ) ) ) . Returns ( false ) ;
323+ insp . Setup ( i => i . IsRecallOnDataAccess ( It . IsAny < FileInfo > ( ) ) ) . Returns ( false ) ;
324+ var ( builder , processData ) = CreateBuilderWithData ( insp . Object ) ;
325+
326+ var noiseRoot = Directory . CreateDirectory ( Path . Combine ( TestDirectory . FullName , "$RECYCLE.BIN" ) ) ;
327+ var filePath = Path . Combine ( noiseRoot . FullName , "inside.txt" ) ;
328+ await File . WriteAllTextAsync ( filePath , "x" ) ;
329+
330+ builder . AddInventoryPart ( noiseRoot . FullName ) ;
331+ var invPath = Path . Combine ( TestDirectory . FullName , "inv_noise_root_dir.zip" ) ;
332+ await builder . BuildBaseInventoryAsync ( invPath ) ;
333+
334+ var part = builder . Inventory . InventoryParts . Single ( ) ;
335+ part . FileDescriptions . Should ( ) . ContainSingle ( fd => fd . Name == "inside.txt" ) ;
336+ processData . SkippedEntries . Should ( ) . NotContain ( e => e . Name == "$RECYCLE.BIN" ) ;
269337 }
270338
271339 [ Test ]
0 commit comments