ManagedFileSystem.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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 MediaBrowser.Common.Configuration;
  9. using MediaBrowser.Model.IO;
  10. using MediaBrowser.Model.System;
  11. using Microsoft.Extensions.Logging;
  12. using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
  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 = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
  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
  213. if (fileInfo.Attributes.HasFlag(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. result.DirectoryName = fileInfo.DirectoryName;
  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;
  532. if (ext == null)
  533. {
  534. return false;
  535. }
  536. return extensions.Contains(ext, StringComparer.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.EnumerateDirectories("*", enumerationOptions))
  546. .Concat(ToMetadata(directoryInfo.EnumerateFiles("*", enumerationOptions)));
  547. }
  548. private IEnumerable<FileSystemMetadata> ToMetadata(IEnumerable<FileSystemInfo> infos)
  549. {
  550. return infos.Select(GetFileSystemMetadata);
  551. }
  552. public virtual IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
  553. {
  554. return Directory.EnumerateDirectories(path, "*", GetEnumerationOptions(recursive));
  555. }
  556. public virtual IEnumerable<string> GetFilePaths(string path, bool recursive = false)
  557. {
  558. return GetFilePaths(path, null, false, recursive);
  559. }
  560. public virtual IEnumerable<string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
  561. {
  562. var enumerationOptions = GetEnumerationOptions(recursive);
  563. // On linux and osx the search pattern is case sensitive
  564. // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
  565. if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Length == 1)
  566. {
  567. return Directory.EnumerateFiles(path, "*" + extensions[0], enumerationOptions);
  568. }
  569. var files = Directory.EnumerateFiles(path, "*", enumerationOptions);
  570. if (extensions != null && extensions.Length > 0)
  571. {
  572. files = files.Where(i =>
  573. {
  574. var ext = Path.GetExtension(i);
  575. if (ext == null)
  576. {
  577. return false;
  578. }
  579. return extensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
  580. });
  581. }
  582. return files;
  583. }
  584. public virtual IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false)
  585. {
  586. return Directory.EnumerateFileSystemEntries(path, "*", GetEnumerationOptions(recursive));
  587. }
  588. private EnumerationOptions GetEnumerationOptions(bool recursive)
  589. {
  590. return new EnumerationOptions
  591. {
  592. RecurseSubdirectories = recursive,
  593. IgnoreInaccessible = true,
  594. // Don't skip any files.
  595. AttributesToSkip = 0
  596. };
  597. }
  598. }
  599. }