MigrateUserFolders.cs 1.1 KB

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