diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-11-09 12:33:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-09 12:33:25 -0500 |
| commit | 90406d842b8efc6f14a909149ff8143e634f154f (patch) | |
| tree | eee8e9dc308d1ff6313ab0a5cc5ccaae2c750379 /Emby.Common.Implementations/IO/ManagedFileSystem.cs | |
| parent | 15e84cf646a2b5ba16c714ba1c509ae5fed36e04 (diff) | |
| parent | c1ae3ec2ce803b16fa9ecc0981865aa7c9be172b (diff) | |
Merge pull request #2278 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations/IO/ManagedFileSystem.cs')
| -rw-r--r-- | Emby.Common.Implementations/IO/ManagedFileSystem.cs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index 5b965efdc..37b457598 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/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) { 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); } |
