public FileSystemCollector(CollectorOptions?opts = null, Action <CollectObject>?changeHandler = null) : base(opts, changeHandler) { Roots.AddRange(opts?.SelectedDirectories ?? Array.Empty <string>()); if (!Roots.Any()) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { foreach (var driveInfo in DriveInfo.GetDrives()) { if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed) { Roots.Add(driveInfo.Name); } } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Roots.Add("/"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Roots.Add("/"); } } }
public FileSystemSource(XElement element, ILoadingContext context) : base(element, context) { Initialize(); if (element.Element("Roots") == null) { throw new MissingElementException(element, "Roots"); } Roots.AddRange(LoadFileSystemRoots(element.Element("Roots"), context)); Include.AddRange(LoadRules(element.Element("Include"), context)); Exclude.AddRange(LoadRules(element.Element("Exclude"), context)); }
public FileSystemCollector(CollectorOptions?opts = null, Action <CollectObject>?changeHandler = null) : base(opts, changeHandler) { Roots.AddRange(opts?.SelectedDirectories ?? new List <string>()); if (!Roots.Any()) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { foreach (var driveInfo in DriveInfo.GetDrives()) { if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed) { Roots.Add(driveInfo.Name); } } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { foreach (var directory in Directory.EnumerateDirectories("/")) { if (!directory.Equals("/proc") && !directory.Equals("/sys")) { Roots.Add(directory); } else { Log.Debug("Default settings skip directories /proc and /sys because they tend to have non-files which stall the collector."); } } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Roots.Add("/"); } } }
public FileSystemSource(IEnumerable <IFileSystemRoot> roots) { Initialize(); Roots.AddRange(roots); }
internal override void ExecuteInternal(CancellationToken cancellationToken) { if (!string.IsNullOrEmpty(opts.SelectedDirectories)) { Roots.AddRange(opts.SelectedDirectories.Split('^')); } if (!Roots.Any()) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { foreach (var driveInfo in DriveInfo.GetDrives()) { if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed) { Roots.Add(driveInfo.Name); } } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Roots.Add("/"); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Roots.Add("/"); } } foreach (var Root in Roots) { Log.Information("{0} root {1}", Strings.Get("Scanning"), Root); var directories = Directory.EnumerateDirectories(Root, "*", new System.IO.EnumerationOptions() { ReturnSpecialDirectories = false, IgnoreInaccessible = true, RecurseSubdirectories = true }); // Process files in the root TryIterateOnDirectory(Root); if (!opts.SingleThread == true) { ParallelOptions po = new ParallelOptions() { CancellationToken = cancellationToken }; Parallel.ForEach(directories, po, filePath => { TryIterateOnDirectory(filePath); }); } else { foreach (var filePath in directories) { if (cancellationToken.IsCancellationRequested) { break; } TryIterateOnDirectory(filePath); } } } }