update file saving

pull/702/head
Luke Pulverenti 8 years ago
parent 24532f3e2d
commit 48a5fa17b0

@ -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)
{
return attributes & ~attributesToRemove;
@ -564,6 +583,20 @@ namespace Emby.Common.Implementations.IO
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);
}

@ -1892,19 +1892,7 @@ namespace MediaBrowser.Controller.Entities
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);

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

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

@ -265,6 +265,10 @@ namespace MediaBrowser.Providers.Manager
{
_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))

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

Loading…
Cancel
Save