mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Fixing folder renaming in AzureFileSystem
New Combine in IStorageProvider --HG-- branch : dev
This commit is contained in:
@@ -105,6 +105,17 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
|
|||||||
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders(null).First().GetPath());
|
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders(null).First().GetPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CreateFolderWithSubFolder() {
|
||||||
|
_azureBlobStorageProvider.CreateFolder("folder");
|
||||||
|
Assert.AreEqual(0, _azureBlobStorageProvider.ListFolders("folder").Count());
|
||||||
|
|
||||||
|
_azureBlobStorageProvider.CreateFolder("folder/folder");
|
||||||
|
Assert.AreEqual(1, _azureBlobStorageProvider.ListFolders("folder").Count());
|
||||||
|
Assert.AreEqual(0, _azureBlobStorageProvider.ListFiles("folder/folder").Count());
|
||||||
|
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders("folder").First().GetName());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DeleteFolderShouldDeleteFilesAlso() {
|
public void DeleteFolderShouldDeleteFilesAlso() {
|
||||||
_azureBlobStorageProvider.CreateFile("folder/foo1.txt");
|
_azureBlobStorageProvider.CreateFile("folder/foo1.txt");
|
||||||
|
@@ -51,10 +51,42 @@ namespace Orchard.Azure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void EnsurePathIsRelative(string path) {
|
private static void EnsurePathIsRelative(string path) {
|
||||||
if (path.StartsWith("/") || path.StartsWith("http://"))
|
if ( path.StartsWith("/") || path.StartsWith("http://") || path.StartsWith("https://") )
|
||||||
throw new ArgumentException("Path must be relative");
|
throw new ArgumentException("Path must be relative");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Combine(string path1, string path2) {
|
||||||
|
if ( path1 == null) {
|
||||||
|
throw new ArgumentNullException("path1");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( path2 == null ) {
|
||||||
|
throw new ArgumentNullException("path2");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( String.IsNullOrEmpty(path2) ) {
|
||||||
|
return path1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( String.IsNullOrEmpty(path1) ) {
|
||||||
|
return path2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( path2.StartsWith("http://") || path2.StartsWith("https://") )
|
||||||
|
{
|
||||||
|
return path2;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ch = path1[path1.Length - 1];
|
||||||
|
|
||||||
|
if (ch != '/')
|
||||||
|
{
|
||||||
|
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (path1 + path2);
|
||||||
|
}
|
||||||
|
|
||||||
public IStorageFile GetFile(string path) {
|
public IStorageFile GetFile(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
|
|
||||||
@@ -75,7 +107,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
|
|
||||||
string prefix = String.Concat(Container.Name, "/", _root, path);
|
string prefix = String.Concat(Combine(Container.Name, _root), path);
|
||||||
|
|
||||||
if ( !prefix.EndsWith("/") )
|
if ( !prefix.EndsWith("/") )
|
||||||
prefix += "/";
|
prefix += "/";
|
||||||
@@ -121,7 +153,7 @@ namespace Orchard.Azure {
|
|||||||
Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path));
|
Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path));
|
||||||
|
|
||||||
// Creating a virtually hidden file to make the directory an existing concept
|
// Creating a virtually hidden file to make the directory an existing concept
|
||||||
CreateFile(path + "/" + FolderEntry);
|
CreateFile(Combine(path, FolderEntry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +295,8 @@ namespace Orchard.Azure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string GetName() {
|
public string GetName() {
|
||||||
return Path.GetDirectoryName(GetPath() + "/");
|
var path = GetPath();
|
||||||
|
return path.Substring(path.LastIndexOf('/') +1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetPath() {
|
public string GetPath() {
|
||||||
|
@@ -66,7 +66,7 @@ namespace Orchard.Media.Services {
|
|||||||
_storageProvider.CreateFolder(name);
|
_storageProvider.CreateFolder(name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_storageProvider.CreateFolder(mediaPath + "\\" + name);
|
_storageProvider.CreateFolder(_storageProvider.Combine(mediaPath, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFolder(string name) {
|
public void DeleteFolder(string name) {
|
||||||
@@ -79,12 +79,12 @@ namespace Orchard.Media.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFile(string name, string folderName) {
|
public void DeleteFile(string name, string folderName) {
|
||||||
_storageProvider.DeleteFile(folderName + "\\" + name);
|
_storageProvider.DeleteFile(_storageProvider.Combine(folderName, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenameFile(string name, string newName, string folderName) {
|
public void RenameFile(string name, string newName, string folderName) {
|
||||||
if (FileAllowed(newName, false)) {
|
if (FileAllowed(newName, false)) {
|
||||||
_storageProvider.RenameFile(folderName + "\\" + name, folderName + "\\" + newName);
|
_storageProvider.RenameFile(_storageProvider.Combine(folderName, name), _storageProvider.Combine(folderName, newName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,14 +193,14 @@ namespace Orchard.Media.Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string RenameFolderPath(string path, string newName) {
|
private string RenameFolderPath(string path, string newName) {
|
||||||
var lastIndex = path.LastIndexOf("\\");
|
var lastIndex = Math.Max(path.LastIndexOf(Path.DirectorySeparatorChar), path.LastIndexOf(Path.AltDirectorySeparatorChar));
|
||||||
|
|
||||||
if (lastIndex == -1) {
|
if (lastIndex == -1) {
|
||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.Substring(0, lastIndex) + "\\" + newName;
|
return _storageProvider.Combine(path.Substring(0, lastIndex), newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -148,6 +148,10 @@ namespace Orchard.FileSystems.Media {
|
|||||||
File.Move(Map(path), Map(newPath));
|
File.Move(Map(path), Map(newPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Combine(string path1, string path2) {
|
||||||
|
return Path.Combine(path1, path2);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private class FileSystemStorageFile : IStorageFile {
|
private class FileSystemStorageFile : IStorageFile {
|
||||||
|
@@ -12,5 +12,6 @@ namespace Orchard.FileSystems.Media {
|
|||||||
void DeleteFile(string path);
|
void DeleteFile(string path);
|
||||||
void RenameFile(string path, string newPath);
|
void RenameFile(string path, string newPath);
|
||||||
IStorageFile CreateFile(string path);
|
IStorageFile CreateFile(string path);
|
||||||
|
string Combine(string path1, string path2);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user