mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
#19503: Ensuring relative paths are used in AzureFileSystem
Work Item: 19503 --HG-- branch : 1.x extra : rebase_source : 1a0c9fb94630b79d28040aaaf0a53be2d9d1c8b9
This commit is contained in:
@@ -43,17 +43,19 @@ namespace Orchard.Azure {
|
||||
Container.CreateIfNotExist();
|
||||
|
||||
Container.SetPermissions(isPrivate
|
||||
? new BlobContainerPermissions
|
||||
{PublicAccess = BlobContainerPublicAccessType.Off}
|
||||
: new BlobContainerPermissions
|
||||
{PublicAccess = BlobContainerPublicAccessType.Container});
|
||||
? new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Off }
|
||||
: new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void EnsurePathIsRelative(string path) {
|
||||
if ( path.StartsWith("/") || path.StartsWith("http://") || path.StartsWith("https://") )
|
||||
private static string ConvertToRelativeUriPath(string path) {
|
||||
var newPath = path.Replace(@"\", "/");
|
||||
|
||||
if (newPath.StartsWith("/") || newPath.StartsWith("http://") || newPath.StartsWith("https://"))
|
||||
throw new ArgumentException("Path must be relative");
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
||||
public string Combine(string path1, string path2) {
|
||||
@@ -87,7 +89,8 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public IStorageFile GetFile(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(String.Concat(_root, path));
|
||||
@@ -108,9 +111,9 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public IEnumerable<IStorageFile> ListFiles(string path) {
|
||||
path = path ?? String.Empty;
|
||||
|
||||
EnsurePathIsRelative(path);
|
||||
path = path ?? String.Empty;
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
string prefix = Combine(Combine(Container.Name, _root), path);
|
||||
|
||||
@@ -128,9 +131,10 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public IEnumerable<IStorageFolder> ListFolders(string path) {
|
||||
path = path ?? String.Empty;
|
||||
|
||||
EnsurePathIsRelative(path);
|
||||
path = path ?? String.Empty;
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
|
||||
// return root folders
|
||||
@@ -175,7 +179,7 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public void CreateFolder(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path));
|
||||
|
||||
@@ -193,7 +197,7 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public void DeleteFolder(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureDirectoryExists(String.Concat(_root, path));
|
||||
@@ -208,8 +212,8 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public void RenameFolder(string path, string newPath) {
|
||||
EnsurePathIsRelative(path);
|
||||
EnsurePathIsRelative(newPath);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
newPath = ConvertToRelativeUriPath(newPath);
|
||||
|
||||
if (!path.EndsWith("/"))
|
||||
path += "/";
|
||||
@@ -236,7 +240,7 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public void DeleteFile(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(Combine(_root, path));
|
||||
@@ -246,8 +250,8 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public void RenameFile(string path, string newPath) {
|
||||
EnsurePathIsRelative(path);
|
||||
EnsurePathIsRelative(newPath);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
newPath = ConvertToRelativeUriPath(newPath);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(String.Concat(_root, path));
|
||||
@@ -261,7 +265,7 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public IStorageFile CreateFile(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
if (Container.BlobExists(String.Concat(_root, path))) {
|
||||
throw new ArgumentException("File " + path + " already exists");
|
||||
@@ -287,7 +291,7 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public string GetPublicUrl(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(String.Concat(_root, path));
|
||||
|
||||
Reference in New Issue
Block a user