aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/IO
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-12 01:09:16 -0400
committerGitHub <noreply@github.com>2017-05-12 01:09:16 -0400
commit275fe6622056d134fdf4737319507c4c51d3f389 (patch)
tree5fb9b96bf0aa3be26dec14313057383af71d5824 /Emby.Common.Implementations/IO
parente06563831e0f7a5e9a6120ab16decb05a0cde8f7 (diff)
parent911de889b1e941c29ee0d7ff68d728fc009b745f (diff)
Merge pull request #2630 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations/IO')
-rw-r--r--Emby.Common.Implementations/IO/ManagedFileSystem.cs58
-rw-r--r--Emby.Common.Implementations/IO/SharpCifsFileSystem.cs25
2 files changed, 64 insertions, 19 deletions
diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs
index 6cbf397585..7d14e521f3 100644
--- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs
@@ -518,6 +518,49 @@ namespace Emby.Common.Implementations.IO
}
}
+ public void SetAttributes(string path, bool isHidden, bool isReadOnly)
+ {
+ if (_sharpCifsFileSystem.IsEnabledForPath(path))
+ {
+ _sharpCifsFileSystem.SetAttributes(path, isHidden, isReadOnly);
+ return;
+ }
+
+ var info = GetFileInfo(path);
+
+ if (!info.Exists)
+ {
+ return;
+ }
+
+ if (info.IsReadOnly == isReadOnly && info.IsHidden == isHidden)
+ {
+ return;
+ }
+
+ var attributes = File.GetAttributes(path);
+
+ if (isReadOnly)
+ {
+ attributes = attributes | FileAttributes.ReadOnly;
+ }
+ else
+ {
+ attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
+ }
+
+ if (isHidden)
+ {
+ attributes = attributes | FileAttributes.Hidden;
+ }
+ else
+ {
+ attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
+ }
+
+ File.SetAttributes(path, attributes);
+ }
+
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
{
return attributes & ~attributesToRemove;
@@ -690,20 +733,7 @@ namespace Emby.Common.Implementations.IO
return;
}
- var fileInfo = GetFileInfo(path);
-
- if (fileInfo.Exists)
- {
- if (fileInfo.IsHidden)
- {
- SetHidden(path, false);
- }
- if (fileInfo.IsReadOnly)
- {
- SetReadOnly(path, false);
- }
- }
-
+ SetAttributes(path, false, false);
File.Delete(path);
}
diff --git a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs
index 283bcdef05..64cac76230 100644
--- a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs
+++ b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs
@@ -166,23 +166,38 @@ namespace Emby.Common.Implementations.IO
public void SetHidden(string path, bool isHidden)
{
var file = CreateSmbFile(path);
+ SetHidden(file, isHidden);
+ }
+
+ public void SetReadOnly(string path, bool isReadOnly)
+ {
+ var file = CreateSmbFile(path);
+ SetReadOnly(file, isReadOnly);
+ }
+
+ public void SetAttributes(string path, bool isHidden, bool isReadOnly)
+ {
+ var file = CreateSmbFile(path);
+ SetHidden(file, isHidden);
+ SetReadOnly(file, isReadOnly);
+ }
+ private void SetHidden(SmbFile file, bool isHidden)
+ {
var isCurrentlyHidden = file.IsHidden();
if (isCurrentlyHidden && !isHidden)
{
- file.SetAttributes(file.GetAttributes() & ~SmbFile.AttrReadonly);
+ file.SetAttributes(file.GetAttributes() & ~SmbFile.AttrHidden);
}
else if (!isCurrentlyHidden && isHidden)
{
- file.SetAttributes(file.GetAttributes() | SmbFile.AttrReadonly);
+ file.SetAttributes(file.GetAttributes() | SmbFile.AttrHidden);
}
}
- public void SetReadOnly(string path, bool isReadOnly)
+ private void SetReadOnly(SmbFile file, bool isReadOnly)
{
- var file = CreateSmbFile(path);
-
var isCurrentlyReadOnly = !file.CanWrite();
if (isCurrentlyReadOnly && !isReadOnly)