update file saving

This commit is contained in:
Luke Pulverenti 2016-11-09 12:24:57 -05:00
parent 24532f3e2d
commit 48a5fa17b0
6 changed files with 47 additions and 14 deletions

View File

@ -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);
} }

View File

@ -1892,19 +1892,7 @@ namespace MediaBrowser.Controller.Entities
if (info.IsLocalFile) if (info.IsLocalFile)
{ {
// Delete the source file FileSystem.DeleteFile(info.Path);
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);
}
} }
return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None); return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None);

View File

@ -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))

View File

@ -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; }

View File

@ -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))

View File

@ -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))