MigrateUserFolders.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Controller;
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. namespace MediaBrowser.Server.Startup.Common.Migrations
  7. {
  8. public class MigrateUserFolders : IVersionMigration
  9. {
  10. private readonly IServerApplicationPaths _appPaths;
  11. private readonly IFileSystem _fileSystem;
  12. public MigrateUserFolders(IServerApplicationPaths appPaths, IFileSystem fileSystem)
  13. {
  14. _appPaths = appPaths;
  15. _fileSystem = fileSystem;
  16. }
  17. public void Run()
  18. {
  19. try
  20. {
  21. var rootPath = _appPaths.RootFolderPath;
  22. var folders = new DirectoryInfo(rootPath).EnumerateDirectories("*", SearchOption.TopDirectoryOnly).Where(i => !string.Equals(i.Name, "default", StringComparison.OrdinalIgnoreCase))
  23. .ToList();
  24. foreach (var folder in folders)
  25. {
  26. _fileSystem.DeleteDirectory(folder.FullName, true);
  27. }
  28. }
  29. catch (IOException)
  30. {
  31. }
  32. }
  33. }
  34. }