mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-18 19:51:45 +08:00
Fix packaging bug
--HG-- branch : dev
This commit is contained in:
@@ -19,6 +19,10 @@ namespace Orchard.Tests.Stubs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string ReadFile(string path) {
|
public string ReadFile(string path) {
|
||||||
|
return ReadFile(path, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadFile(string path, bool actualContent) {
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -29,6 +33,10 @@ namespace Orchard.Tests.Stubs {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CopyFileTo(string virtualPath, Stream destination, bool actualContent) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public IVolatileToken WhenPathChanges(string path) {
|
public IVolatileToken WhenPathChanges(string path) {
|
||||||
return new Token {IsCurrent = true};
|
return new Token {IsCurrent = true};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
|
|
||||||
bool FileExists(string virtualPath);
|
bool FileExists(string virtualPath);
|
||||||
string ReadFile(string virtualPath);
|
string ReadFile(string virtualPath);
|
||||||
|
string ReadFile(string virtualPath, bool actualContent);
|
||||||
void CopyFileTo(string virtualPath, Stream destination);
|
void CopyFileTo(string virtualPath, Stream destination);
|
||||||
|
void CopyFileTo(string virtualPath, Stream destination, bool actualContent);
|
||||||
|
|
||||||
IVolatileToken WhenPathChanges(string virtualPath);
|
IVolatileToken WhenPathChanges(string virtualPath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ using Orchard.FileSystems.VirtualPath;
|
|||||||
|
|
||||||
namespace Orchard.FileSystems.WebSite {
|
namespace Orchard.FileSystems.WebSite {
|
||||||
public class WebSiteFolder : IWebSiteFolder {
|
public class WebSiteFolder : IWebSiteFolder {
|
||||||
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
private readonly IVirtualPathMonitor _virtualPathMonitor;
|
||||||
|
|
||||||
public WebSiteFolder(IVirtualPathMonitor virtualPathMonitor) {
|
public WebSiteFolder(IVirtualPathMonitor virtualPathMonitor, IVirtualPathProvider virtualPathProvider) {
|
||||||
_virtualPathMonitor = virtualPathMonitor;
|
_virtualPathMonitor = virtualPathMonitor;
|
||||||
|
_virtualPathProvider = virtualPathProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ListDirectories(string virtualPath) {
|
public IEnumerable<string> ListDirectories(string virtualPath) {
|
||||||
@@ -31,19 +33,50 @@ namespace Orchard.FileSystems.WebSite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string ReadFile(string virtualPath) {
|
public string ReadFile(string virtualPath) {
|
||||||
|
return ReadFile(virtualPath, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadFile(string virtualPath, bool actualContent) {
|
||||||
if (!HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
|
if (!HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
if (actualContent) {
|
||||||
using (var reader = new StreamReader(stream)) {
|
var physicalPath = _virtualPathProvider.MapPath(virtualPath);
|
||||||
return reader.ReadToEnd();
|
using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read)) {
|
||||||
|
using (var reader = new StreamReader(stream)) {
|
||||||
|
return reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||||
|
using (var reader = new StreamReader(stream)) {
|
||||||
|
return reader.ReadToEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyFileTo(string virtualPath, Stream destination) {
|
public void CopyFileTo(string virtualPath, Stream destination) {
|
||||||
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
CopyFileTo(virtualPath, destination, false/*actualContent*/);
|
||||||
stream.CopyTo(destination);
|
}
|
||||||
|
|
||||||
|
public void CopyFileTo(string virtualPath, Stream destination, bool actualContent) {
|
||||||
|
if (actualContent) {
|
||||||
|
// This is an unfortunate side-effect of the dynamic compilation work.
|
||||||
|
// Orchard has a custom virtual path provider which adds "<@Assembly xxx@>"
|
||||||
|
// directives to WebForm view files. There are cases when this side effect
|
||||||
|
// is not expected by the consumer of the WebSiteFolder API.
|
||||||
|
// The workaround here is to go directly to the file system.
|
||||||
|
var physicalPath = _virtualPathProvider.MapPath(virtualPath);
|
||||||
|
using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read)) {
|
||||||
|
stream.CopyTo(destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
using (var stream = VirtualPathProvider.OpenFile(Normalize(virtualPath))) {
|
||||||
|
stream.CopyTo(destination);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ namespace Orchard.Packaging {
|
|||||||
var partUri = PackUriHelper.CreatePartUri(new Uri(context.TargetPath + relativePath, UriKind.Relative));
|
var partUri = PackUriHelper.CreatePartUri(new Uri(context.TargetPath + relativePath, UriKind.Relative));
|
||||||
var packagePart = context.Package.CreatePart(partUri, contentType);
|
var packagePart = context.Package.CreatePart(partUri, contentType);
|
||||||
using (var stream = packagePart.GetStream(FileMode.Create, FileAccess.Write)) {
|
using (var stream = packagePart.GetStream(FileMode.Create, FileAccess.Write)) {
|
||||||
context.SourceFolder.CopyFileTo(context.SourcePath + relativePath, stream);
|
context.SourceFolder.CopyFileTo(context.SourcePath + relativePath, stream, true/*actualContent*/);
|
||||||
}
|
}
|
||||||
return partUri;
|
return partUri;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user