ManagedFileSystem.cs 25 KB

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