ManagedFileSystem.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using Jellyfin.Extensions;
  9. using MediaBrowser.Common.Configuration;
  10. using MediaBrowser.Model.IO;
  11. using MediaBrowser.Model.System;
  12. using Microsoft.Extensions.Logging;
  13. namespace Emby.Server.Implementations.IO
  14. {
  15. /// <summary>
  16. /// Class ManagedFileSystem.
  17. /// </summary>
  18. public class ManagedFileSystem : IFileSystem
  19. {
  20. protected ILogger<ManagedFileSystem> Logger;
  21. private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
  22. private readonly string _tempPath;
  23. private static readonly bool _isEnvironmentCaseInsensitive = OperatingSystem.IsWindows();
  24. public ManagedFileSystem(
  25. ILogger<ManagedFileSystem> logger,
  26. IApplicationPaths applicationPaths)
  27. {
  28. Logger = logger;
  29. _tempPath = applicationPaths.TempDirectory;
  30. }
  31. public virtual void AddShortcutHandler(IShortcutHandler handler)
  32. {
  33. _shortcutHandlers.Add(handler);
  34. }
  35. /// <summary>
  36. /// Determines whether the specified filename is shortcut.
  37. /// </summary>
  38. /// <param name="filename">The filename.</param>
  39. /// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
  40. /// <exception cref="ArgumentNullException">filename</exception>
  41. public virtual bool IsShortcut(string filename)
  42. {
  43. if (string.IsNullOrEmpty(filename))
  44. {
  45. throw new ArgumentNullException(nameof(filename));
  46. }
  47. var extension = Path.GetExtension(filename);
  48. return _shortcutHandlers.Any(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  49. }
  50. /// <summary>
  51. /// Resolves the shortcut.
  52. /// </summary>
  53. /// <param name="filename">The filename.</param>
  54. /// <returns>System.String.</returns>
  55. /// <exception cref="ArgumentNullException">filename</exception>
  56. public virtual string? ResolveShortcut(string filename)
  57. {
  58. if (string.IsNullOrEmpty(filename))
  59. {
  60. throw new ArgumentNullException(nameof(filename));
  61. }
  62. var extension = Path.GetExtension(filename);
  63. var handler = _shortcutHandlers.Find(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  64. return handler?.Resolve(filename);
  65. }
  66. public virtual string MakeAbsolutePath(string folderPath, string filePath)
  67. {
  68. // path is actually a stream
  69. if (string.IsNullOrWhiteSpace(filePath) || filePath.Contains("://", StringComparison.Ordinal))
  70. {
  71. return filePath;
  72. }
  73. if (filePath.Length > 3 && filePath[1] == ':' && filePath[2] == '/')
  74. {
  75. // absolute local path
  76. return filePath;
  77. }
  78. // unc path
  79. if (filePath.StartsWith("\\\\", StringComparison.Ordinal))
  80. {
  81. return filePath;
  82. }
  83. var firstChar = filePath[0];
  84. if (firstChar == '/')
  85. {
  86. // for this we don't really know
  87. return filePath;
  88. }
  89. // relative path
  90. if (firstChar == '\\')
  91. {
  92. filePath = filePath.Substring(1);
  93. }
  94. try
  95. {
  96. return Path.GetFullPath(Path.Combine(folderPath, filePath));
  97. }
  98. catch (ArgumentException)
  99. {
  100. return filePath;
  101. }
  102. catch (PathTooLongException)
  103. {
  104. return filePath;
  105. }
  106. catch (NotSupportedException)
  107. {
  108. return filePath;
  109. }
  110. }
  111. /// <summary>
  112. /// Creates the shortcut.
  113. /// </summary>
  114. /// <param name="shortcutPath">The shortcut path.</param>
  115. /// <param name="target">The target.</param>
  116. /// <exception cref="ArgumentNullException">The shortcutPath or target is null.</exception>
  117. public virtual void CreateShortcut(string shortcutPath, string target)
  118. {
  119. if (string.IsNullOrEmpty(shortcutPath))
  120. {
  121. throw new ArgumentNullException(nameof(shortcutPath));
  122. }
  123. if (string.IsNullOrEmpty(target))
  124. {
  125. throw new ArgumentNullException(nameof(target));
  126. }
  127. var extension = Path.GetExtension(shortcutPath);
  128. var handler = _shortcutHandlers.Find(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
  129. if (handler != null)
  130. {
  131. handler.Create(shortcutPath, target);
  132. }
  133. else
  134. {
  135. throw new NotImplementedException();
  136. }
  137. }
  138. /// <summary>
  139. /// Returns a <see cref="FileSystemMetadata"/> object for the specified file or directory path.
  140. /// </summary>
  141. /// <param name="path">A path to a file or directory.</param>
  142. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  143. /// <remarks>If the specified path points to a directory, the returned <see cref="FileSystemMetadata"/> object's
  144. /// <see cref="FileSystemMetadata.IsDirectory"/> property will be set to true and all other properties will reflect the properties of the directory.</remarks>
  145. public virtual FileSystemMetadata GetFileSystemInfo(string path)
  146. {
  147. // Take a guess to try and avoid two file system hits, but we'll double-check by calling Exists
  148. if (Path.HasExtension(path))
  149. {
  150. var fileInfo = new FileInfo(path);
  151. if (fileInfo.Exists)
  152. {
  153. return GetFileSystemMetadata(fileInfo);
  154. }
  155. return GetFileSystemMetadata(new DirectoryInfo(path));
  156. }
  157. else
  158. {
  159. var fileInfo = new DirectoryInfo(path);
  160. if (fileInfo.Exists)
  161. {
  162. return GetFileSystemMetadata(fileInfo);
  163. }
  164. return GetFileSystemMetadata(new FileInfo(path));
  165. }
  166. }
  167. /// <summary>
  168. /// Returns a <see cref="FileSystemMetadata"/> object for the specified file path.
  169. /// </summary>
  170. /// <param name="path">A path to a file.</param>
  171. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  172. /// <remarks><para>If the specified path points to a directory, the returned <see cref="FileSystemMetadata"/> object's
  173. /// <see cref="FileSystemMetadata.IsDirectory"/> property and the <see cref="FileSystemMetadata.Exists"/> property will both be set to false.</para>
  174. /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo"/>.</para></remarks>
  175. public virtual FileSystemMetadata GetFileInfo(string path)
  176. {
  177. var fileInfo = new FileInfo(path);
  178. return GetFileSystemMetadata(fileInfo);
  179. }
  180. /// <summary>
  181. /// Returns a <see cref="FileSystemMetadata"/> object for the specified directory path.
  182. /// </summary>
  183. /// <param name="path">A path to a directory.</param>
  184. /// <returns>A <see cref="FileSystemMetadata"/> object.</returns>
  185. /// <remarks><para>If the specified path points to a file, the returned <see cref="FileSystemMetadata"/> object's
  186. /// <see cref="FileSystemMetadata.IsDirectory"/> property will be set to true and the <see cref="FileSystemMetadata.Exists"/> property will be set to false.</para>
  187. /// <para>For automatic handling of files <b>and</b> directories, use <see cref="GetFileSystemInfo"/>.</para></remarks>
  188. public virtual FileSystemMetadata GetDirectoryInfo(string path)
  189. {
  190. var fileInfo = new DirectoryInfo(path);
  191. return GetFileSystemMetadata(fileInfo);
  192. }
  193. private FileSystemMetadata GetFileSystemMetadata(FileSystemInfo info)
  194. {
  195. var result = new FileSystemMetadata
  196. {
  197. Exists = info.Exists,
  198. FullName = info.FullName,
  199. Extension = info.Extension,
  200. Name = info.Name
  201. };
  202. if (result.Exists)
  203. {
  204. result.IsDirectory = info is DirectoryInfo || (info.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
  205. // if (!result.IsDirectory)
  206. //{
  207. // result.IsHidden = (info.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
  208. //}
  209. if (info is FileInfo fileInfo)
  210. {
  211. result.Length = fileInfo.Length;
  212. // Issue #2354 get the size of files behind symbolic links. Also Enum.HasFlag is bad as it boxes!
  213. if ((fileInfo.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
  214. {
  215. try
  216. {
  217. using (Stream thisFileStream = File.OpenRead(fileInfo.FullName))
  218. {
  219. result.Length = thisFileStream.Length;
  220. }
  221. }
  222. catch (FileNotFoundException ex)
  223. {
  224. // Dangling symlinks cannot be detected before opening the file unfortunately...
  225. Logger.LogError(ex, "Reading the file size of the symlink at {Path} failed. Marking the file as not existing.", fileInfo.FullName);
  226. result.Exists = false;
  227. }
  228. }
  229. }
  230. result.CreationTimeUtc = GetCreationTimeUtc(info);
  231. result.LastWriteTimeUtc = GetLastWriteTimeUtc(info);
  232. }
  233. else
  234. {
  235. result.IsDirectory = info is DirectoryInfo;
  236. }
  237. return result;
  238. }
  239. private static ExtendedFileSystemInfo GetExtendedFileSystemInfo(string path)
  240. {
  241. var result = new ExtendedFileSystemInfo();
  242. var info = new FileInfo(path);
  243. if (info.Exists)
  244. {
  245. result.Exists = true;
  246. var attributes = info.Attributes;
  247. result.IsHidden = (attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
  248. result.IsReadOnly = (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
  249. }
  250. return result;
  251. }
  252. /// <summary>
  253. /// Takes a filename and removes invalid characters.
  254. /// </summary>
  255. /// <param name="filename">The filename.</param>
  256. /// <returns>System.String.</returns>
  257. /// <exception cref="ArgumentNullException">The filename is null.</exception>
  258. public string GetValidFilename(string filename)
  259. {
  260. var invalid = Path.GetInvalidFileNameChars();
  261. var first = filename.IndexOfAny(invalid);
  262. if (first == -1)
  263. {
  264. // Fast path for clean strings
  265. return filename;
  266. }
  267. return string.Create(
  268. filename.Length,
  269. (filename, invalid, first),
  270. (chars, state) =>
  271. {
  272. state.filename.AsSpan().CopyTo(chars);
  273. chars[state.first++] = ' ';
  274. var len = chars.Length;
  275. foreach (var c in state.invalid)
  276. {
  277. for (int i = state.first; i < len; i++)
  278. {
  279. if (chars[i] == c)
  280. {
  281. chars[i] = ' ';
  282. }
  283. }
  284. }
  285. });
  286. }
  287. /// <summary>
  288. /// Gets the creation time UTC.
  289. /// </summary>
  290. /// <param name="info">The info.</param>
  291. /// <returns>DateTime.</returns>
  292. public DateTime GetCreationTimeUtc(FileSystemInfo info)
  293. {
  294. // This could throw an error on some file systems that have dates out of range
  295. try
  296. {
  297. return info.CreationTimeUtc;
  298. }
  299. catch (Exception ex)
  300. {
  301. Logger.LogError(ex, "Error determining CreationTimeUtc for {FullName}", info.FullName);
  302. return DateTime.MinValue;
  303. }
  304. }
  305. /// <summary>
  306. /// Gets the creation time UTC.
  307. /// </summary>
  308. /// <param name="path">The path.</param>
  309. /// <returns>DateTime.</returns>
  310. public virtual DateTime GetCreationTimeUtc(string path)
  311. {
  312. return GetCreationTimeUtc(GetFileSystemInfo(path));
  313. }
  314. public virtual DateTime GetCreationTimeUtc(FileSystemMetadata info)
  315. {
  316. return info.CreationTimeUtc;
  317. }
  318. public virtual DateTime GetLastWriteTimeUtc(FileSystemMetadata info)
  319. {
  320. return info.LastWriteTimeUtc;
  321. }
  322. /// <summary>
  323. /// Gets the creation time UTC.
  324. /// </summary>
  325. /// <param name="info">The info.</param>
  326. /// <returns>DateTime.</returns>
  327. public DateTime GetLastWriteTimeUtc(FileSystemInfo info)
  328. {
  329. // This could throw an error on some file systems that have dates out of range
  330. try
  331. {
  332. return info.LastWriteTimeUtc;
  333. }
  334. catch (Exception ex)
  335. {
  336. Logger.LogError(ex, "Error determining LastAccessTimeUtc for {FullName}", info.FullName);
  337. return DateTime.MinValue;
  338. }
  339. }
  340. /// <summary>
  341. /// Gets the last write time UTC.
  342. /// </summary>
  343. /// <param name="path">The path.</param>
  344. /// <returns>DateTime.</returns>
  345. public virtual DateTime GetLastWriteTimeUtc(string path)
  346. {
  347. return GetLastWriteTimeUtc(GetFileSystemInfo(path));
  348. }
  349. public virtual void SetHidden(string path, bool isHidden)
  350. {
  351. if (!OperatingSystem.IsWindows())
  352. {
  353. return;
  354. }
  355. var info = GetExtendedFileSystemInfo(path);
  356. if (info.Exists && info.IsHidden != isHidden)
  357. {
  358. if (isHidden)
  359. {
  360. File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
  361. }
  362. else
  363. {
  364. var attributes = File.GetAttributes(path);
  365. attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
  366. File.SetAttributes(path, attributes);
  367. }
  368. }
  369. }
  370. public virtual void SetAttributes(string path, bool isHidden, bool isReadOnly)
  371. {
  372. if (!OperatingSystem.IsWindows())
  373. {
  374. return;
  375. }
  376. var info = GetExtendedFileSystemInfo(path);
  377. if (!info.Exists)
  378. {
  379. return;
  380. }
  381. if (info.IsReadOnly == isReadOnly && info.IsHidden == isHidden)
  382. {
  383. return;
  384. }
  385. var attributes = File.GetAttributes(path);
  386. if (isReadOnly)
  387. {
  388. attributes = attributes | FileAttributes.ReadOnly;
  389. }
  390. else
  391. {
  392. attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
  393. }
  394. if (isHidden)
  395. {
  396. attributes = attributes | FileAttributes.Hidden;
  397. }
  398. else
  399. {
  400. attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
  401. }
  402. File.SetAttributes(path, attributes);
  403. }
  404. private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
  405. {
  406. return attributes & ~attributesToRemove;
  407. }
  408. /// <summary>
  409. /// Swaps the files.
  410. /// </summary>
  411. /// <param name="file1">The file1.</param>
  412. /// <param name="file2">The file2.</param>
  413. public virtual void SwapFiles(string file1, string file2)
  414. {
  415. if (string.IsNullOrEmpty(file1))
  416. {
  417. throw new ArgumentNullException(nameof(file1));
  418. }
  419. if (string.IsNullOrEmpty(file2))
  420. {
  421. throw new ArgumentNullException(nameof(file2));
  422. }
  423. var temp1 = Path.Combine(_tempPath, Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
  424. // Copying over will fail against hidden files
  425. SetHidden(file1, false);
  426. SetHidden(file2, false);
  427. Directory.CreateDirectory(_tempPath);
  428. File.Copy(file1, temp1, true);
  429. File.Copy(file2, file1, true);
  430. File.Copy(temp1, file2, true);
  431. }
  432. public virtual bool ContainsSubPath(string parentPath, string path)
  433. {
  434. if (string.IsNullOrEmpty(parentPath))
  435. {
  436. throw new ArgumentNullException(nameof(parentPath));
  437. }
  438. if (string.IsNullOrEmpty(path))
  439. {
  440. throw new ArgumentNullException(nameof(path));
  441. }
  442. return path.Contains(
  443. Path.TrimEndingDirectorySeparator(parentPath) + Path.DirectorySeparatorChar,
  444. _isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
  445. }
  446. public virtual string NormalizePath(string path)
  447. {
  448. if (string.IsNullOrEmpty(path))
  449. {
  450. throw new ArgumentNullException(nameof(path));
  451. }
  452. if (path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
  453. {
  454. return path;
  455. }
  456. return Path.TrimEndingDirectorySeparator(path);
  457. }
  458. public virtual bool AreEqual(string path1, string path2)
  459. {
  460. if (path1 == null && path2 == null)
  461. {
  462. return true;
  463. }
  464. if (path1 == null || path2 == null)
  465. {
  466. return false;
  467. }
  468. return string.Equals(
  469. NormalizePath(path1),
  470. NormalizePath(path2),
  471. _isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
  472. }
  473. public virtual string GetFileNameWithoutExtension(FileSystemMetadata info)
  474. {
  475. if (info.IsDirectory)
  476. {
  477. return info.Name;
  478. }
  479. return Path.GetFileNameWithoutExtension(info.FullName);
  480. }
  481. public virtual bool IsPathFile(string path)
  482. {
  483. // Cannot use Path.IsPathRooted because it returns false under mono when using windows-based paths, e.g. C:\\
  484. if (path.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1 &&
  485. !path.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
  486. {
  487. return false;
  488. }
  489. return true;
  490. }
  491. public virtual void DeleteFile(string path)
  492. {
  493. SetAttributes(path, false, false);
  494. File.Delete(path);
  495. }
  496. public virtual List<FileSystemMetadata> GetDrives()
  497. {
  498. // check for ready state to avoid waiting for drives to timeout
  499. // some drives on linux have no actual size or are used for other purposes
  500. return DriveInfo.GetDrives().Where(d => d.IsReady && d.TotalSize != 0 && d.DriveType != DriveType.Ram)
  501. .Select(d => new FileSystemMetadata
  502. {
  503. Name = d.Name,
  504. FullName = d.RootDirectory.FullName,
  505. IsDirectory = true
  506. }).ToList();
  507. }
  508. public virtual IEnumerable<FileSystemMetadata> GetDirectories(string path, bool recursive = false)
  509. {
  510. return ToMetadata(new DirectoryInfo(path).EnumerateDirectories("*", GetEnumerationOptions(recursive)));
  511. }
  512. public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
  513. {
  514. return GetFiles(path, null, false, recursive);
  515. }
  516. public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
  517. {
  518. var enumerationOptions = GetEnumerationOptions(recursive);
  519. // On linux and osx the search pattern is case sensitive
  520. // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
  521. if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Count == 1)
  522. {
  523. return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], enumerationOptions));
  524. }
  525. var files = new DirectoryInfo(path).EnumerateFiles("*", enumerationOptions);
  526. if (extensions != null && extensions.Count > 0)
  527. {
  528. files = files.Where(i =>
  529. {
  530. var ext = i.Extension.AsSpan();
  531. if (ext.IsEmpty)
  532. {
  533. return false;
  534. }
  535. return extensions.Contains(ext, StringComparison.OrdinalIgnoreCase);
  536. });
  537. }
  538. return ToMetadata(files);
  539. }
  540. public virtual IEnumerable<FileSystemMetadata> GetFileSystemEntries(string path, bool recursive = false)
  541. {
  542. var directoryInfo = new DirectoryInfo(path);
  543. var enumerationOptions = GetEnumerationOptions(recursive);
  544. return ToMetadata(directoryInfo.EnumerateFileSystemInfos("*", enumerationOptions));
  545. }
  546. private IEnumerable<FileSystemMetadata> ToMetadata(IEnumerable<FileSystemInfo> infos)
  547. {
  548. return infos.Select(GetFileSystemMetadata);
  549. }
  550. public virtual IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
  551. {
  552. return Directory.EnumerateDirectories(path, "*", GetEnumerationOptions(recursive));
  553. }
  554. public virtual IEnumerable<string> GetFilePaths(string path, bool recursive = false)
  555. {
  556. return GetFilePaths(path, null, false, recursive);
  557. }
  558. public virtual IEnumerable<string> GetFilePaths(string path, string[]? extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
  559. {
  560. var enumerationOptions = GetEnumerationOptions(recursive);
  561. // On linux and osx the search pattern is case sensitive
  562. // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
  563. if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Length == 1)
  564. {
  565. return Directory.EnumerateFiles(path, "*" + extensions[0], enumerationOptions);
  566. }
  567. var files = Directory.EnumerateFiles(path, "*", enumerationOptions);
  568. if (extensions != null && extensions.Length > 0)
  569. {
  570. files = files.Where(i =>
  571. {
  572. var ext = Path.GetExtension(i.AsSpan());
  573. if (ext.IsEmpty)
  574. {
  575. return false;
  576. }
  577. return extensions.Contains(ext, StringComparison.OrdinalIgnoreCase);
  578. });
  579. }
  580. return files;
  581. }
  582. public virtual IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false)
  583. {
  584. return Directory.EnumerateFileSystemEntries(path, "*", GetEnumerationOptions(recursive));
  585. }
  586. private EnumerationOptions GetEnumerationOptions(bool recursive)
  587. {
  588. return new EnumerationOptions
  589. {
  590. RecurseSubdirectories = recursive,
  591. IgnoreInaccessible = true,
  592. // Don't skip any files.
  593. AttributesToSkip = 0
  594. };
  595. }
  596. }
  597. }