MigrateUserFolders.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 = _fileSystem.GetDirectories(rootPath)
  23. .Where(i => !string.Equals(i.Name, "default", StringComparison.OrdinalIgnoreCase))
  24. .ToList();
  25. foreach (var folder in folders)
  26. {
  27. _fileSystem.DeleteDirectory(folder.FullName, true);
  28. }
  29. }
  30. catch (IOException)
  31. {
  32. }
  33. }
  34. }
  35. }