aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-12 14:19:33 -0400
committerGitHub <noreply@github.com>2017-05-12 14:19:33 -0400
commit1a6ee3d48aec8aa592ea2b0aab9560292ce717d6 (patch)
tree558b953b1e01a16bd47d902c841cc747a50e0ae7 /Emby.Common.Implementations
parent65db32b1f878cd478e9f4b2b4c988890a7ca47c9 (diff)
parent3cdb75190d457cbb3bed91bf79bfb4816cad29e2 (diff)
Merge pull request #2633 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Common.Implementations')
-rw-r--r--Emby.Common.Implementations/IO/ManagedFileSystem.cs79
-rw-r--r--Emby.Common.Implementations/IO/SharpCifsFileSystem.cs30
-rw-r--r--Emby.Common.Implementations/project.json2
3 files changed, 89 insertions, 22 deletions
diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs
index 3ed4f650f..7d14e521f 100644
--- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs
@@ -392,10 +392,27 @@ namespace Emby.Common.Implementations.IO
if (_supportsAsyncFileStreams && isAsync)
{
- return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144, true);
+ return GetFileStream(path, mode, access, share, FileOpenOptions.Asynchronous);
}
- return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144);
+ return GetFileStream(path, mode, access, share, FileOpenOptions.None);
+ }
+
+ public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, FileOpenOptions fileOpenOptions)
+ {
+ if (_sharpCifsFileSystem.IsEnabledForPath(path))
+ {
+ return _sharpCifsFileSystem.GetFileStream(path, mode, access, share);
+ }
+
+ var defaultBufferSize = 4096;
+ return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), defaultBufferSize, GetFileOptions(fileOpenOptions));
+ }
+
+ private FileOptions GetFileOptions(FileOpenOptions mode)
+ {
+ var val = (int)mode;
+ return (FileOptions)val;
}
private FileMode GetFileMode(FileOpenMode mode)
@@ -501,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;
@@ -673,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 0a407d64f..64cac7623 100644
--- a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs
+++ b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs
@@ -53,6 +53,11 @@ namespace Emby.Common.Implementations.IO
if (separator == '/')
{
result = result.Replace('\\', '/');
+
+ if (result.StartsWith("smb:/", StringComparison.OrdinalIgnoreCase) && !result.StartsWith("smb://", StringComparison.OrdinalIgnoreCase))
+ {
+ result = result.Replace("smb:/", "smb://");
+ }
}
return result;
@@ -161,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)
diff --git a/Emby.Common.Implementations/project.json b/Emby.Common.Implementations/project.json
index 674101e8a..ff60c740e 100644
--- a/Emby.Common.Implementations/project.json
+++ b/Emby.Common.Implementations/project.json
@@ -45,7 +45,7 @@
"System.Net.Requests": "4.3.0",
"System.Xml.ReaderWriter": "4.3.0",
"System.Xml.XmlSerializer": "4.3.0",
- "System.Net.Http": "4.3.0",
+ "System.Net.Http": "4.3.2",
"System.Net.Primitives": "4.3.0",
"System.Net.Sockets": "4.3.0",
"System.Net.NetworkInformation": "4.3.0",