mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-10-30 18:22:48 -04:00 
			
		
		
		
	Fix empty image folder removal for legacy locations Original-merge: 476dc01f4d5bf0fdf391935ef0759b0583bf7026 Merged-by: Bond-009 <bond.009@outlook.com> Backported-by: Joshua M. Boniface <joshua@boniface.me>
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.IO;
 | |
| using System.Linq;
 | |
| using MediaBrowser.Model.IO;
 | |
| using Microsoft.Extensions.Logging;
 | |
| 
 | |
| namespace MediaBrowser.Controller.IO;
 | |
| 
 | |
| /// <summary>
 | |
| /// Helper methods for file system management.
 | |
| /// </summary>
 | |
| public static class FileSystemHelper
 | |
| {
 | |
|     /// <summary>
 | |
|     /// Deletes the file.
 | |
|     /// </summary>
 | |
|     /// <param name="fileSystem">The fileSystem.</param>
 | |
|     /// <param name="path">The path.</param>
 | |
|     /// <param name="logger">The logger.</param>
 | |
|     public static void DeleteFile(IFileSystem fileSystem, string path, ILogger logger)
 | |
|     {
 | |
|         try
 | |
|         {
 | |
|             fileSystem.DeleteFile(path);
 | |
|         }
 | |
|         catch (UnauthorizedAccessException ex)
 | |
|         {
 | |
|             logger.LogError(ex, "Error deleting file {Path}", path);
 | |
|         }
 | |
|         catch (IOException ex)
 | |
|         {
 | |
|             logger.LogError(ex, "Error deleting file {Path}", path);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     /// <summary>
 | |
|     /// Recursively delete empty folders.
 | |
|     /// </summary>
 | |
|     /// <param name="fileSystem">The fileSystem.</param>
 | |
|     /// <param name="path">The path.</param>
 | |
|     /// <param name="logger">The logger.</param>
 | |
|     public static void DeleteEmptyFolders(IFileSystem fileSystem, string path, ILogger logger)
 | |
|     {
 | |
|         foreach (var directory in fileSystem.GetDirectoryPaths(path))
 | |
|         {
 | |
|             DeleteEmptyFolders(fileSystem, directory, logger);
 | |
|             if (!fileSystem.GetFileSystemEntryPaths(directory).Any())
 | |
|             {
 | |
|                 try
 | |
|                 {
 | |
|                     Directory.Delete(directory, false);
 | |
|                 }
 | |
|                 catch (UnauthorizedAccessException ex)
 | |
|                 {
 | |
|                     logger.LogError(ex, "Error deleting directory {Path}", directory);
 | |
|                 }
 | |
|                 catch (IOException ex)
 | |
|                 {
 | |
|                     logger.LogError(ex, "Error deleting directory {Path}", directory);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |