소스 검색

update file saving

Luke Pulverenti 8 년 전
부모
커밋
48a5fa17b0

+ 33 - 0
Emby.Common.Implementations/IO/ManagedFileSystem.cs

@@ -419,6 +419,25 @@ namespace Emby.Common.Implementations.IO
             }
             }
         }
         }
 
 
+        public void SetReadOnly(string path, bool isReadOnly)
+        {
+            var info = GetFileInfo(path);
+
+            if (info.Exists && info.IsReadOnly != isReadOnly)
+            {
+                if (isReadOnly)
+                {
+                    File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.ReadOnly);
+                }
+                else
+                {
+                    FileAttributes attributes = File.GetAttributes(path);
+                    attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
+                    File.SetAttributes(path, attributes);
+                }
+            }
+        }
+
         private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
         private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
         {
         {
             return attributes & ~attributesToRemove;
             return attributes & ~attributesToRemove;
@@ -564,6 +583,20 @@ namespace Emby.Common.Implementations.IO
 
 
         public void DeleteFile(string path)
         public void DeleteFile(string path)
         {
         {
+            var fileInfo = GetFileInfo(path);
+
+            if (fileInfo.Exists)
+            {
+                if (fileInfo.IsHidden)
+                {
+                    SetHidden(path, false);
+                }
+                if (fileInfo.IsReadOnly)
+                {
+                    SetReadOnly(path, false);
+                }
+            }
+
             File.Delete(path);
             File.Delete(path);
         }
         }
 
 

+ 1 - 13
MediaBrowser.Controller/Entities/BaseItem.cs

@@ -1892,19 +1892,7 @@ namespace MediaBrowser.Controller.Entities
 
 
             if (info.IsLocalFile)
             if (info.IsLocalFile)
             {
             {
-                // Delete the source file
-                var currentFile = FileSystem.GetFileInfo(info.Path);
-
-                // Deletion will fail if the file is hidden so remove the attribute first
-                if (currentFile.Exists)
-                {
-                    if (currentFile.IsHidden)
-                    {
-                        FileSystem.SetHidden(currentFile.FullName, false);
-                    }
-
-                    FileSystem.DeleteFile(currentFile.FullName);
-                }
+                FileSystem.DeleteFile(info.Path);
             }
             }
 
 
             return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);
             return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);

+ 4 - 1
MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs

@@ -226,9 +226,12 @@ namespace MediaBrowser.LocalMetadata.Savers
                 if (file.IsHidden)
                 if (file.IsHidden)
                 {
                 {
                     FileSystem.SetHidden(path, false);
                     FileSystem.SetHidden(path, false);
-
                     wasHidden = true;
                     wasHidden = true;
                 }
                 }
+                if (file.IsReadOnly)
+                {
+                    FileSystem.SetReadOnly(path, false);
+                }
             }
             }
 
 
             using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
             using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))

+ 1 - 0
MediaBrowser.Model/IO/IFileSystem.cs

@@ -305,6 +305,7 @@ namespace MediaBrowser.Model.IO
         IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false);
         IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false);
 
 
         void SetHidden(string path, bool isHidden);
         void SetHidden(string path, bool isHidden);
+        void SetReadOnly(string path, bool isHidden);
 
 
         char DirectorySeparatorChar { get; }
         char DirectorySeparatorChar { get; }
 
 

+ 4 - 0
MediaBrowser.Providers/Manager/ImageSaver.cs

@@ -265,6 +265,10 @@ namespace MediaBrowser.Providers.Manager
                     {
                     {
                         _fileSystem.SetHidden(file.FullName, false);
                         _fileSystem.SetHidden(file.FullName, false);
                     }
                     }
+                    if (file.IsReadOnly)
+                    {
+                        _fileSystem.SetReadOnly(path, false);
+                    }
                 }
                 }
 
 
                 using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
                 using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))

+ 4 - 0
MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs

@@ -221,6 +221,10 @@ namespace MediaBrowser.XbmcMetadata.Savers
 
 
                     wasHidden = true;
                     wasHidden = true;
                 }
                 }
+                if (file.IsReadOnly)
+                {
+                    FileSystem.SetReadOnly(path, false);
+                }
             }
             }
 
 
             using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
             using (var filestream = FileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))