Fix packaging bug

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-19 17:12:15 -07:00
parent dc1a461f1b
commit b4e7ab7679
4 changed files with 50 additions and 7 deletions

View File

@@ -19,6 +19,10 @@ namespace Orchard.Tests.Stubs {
}
public string ReadFile(string path) {
return ReadFile(path, false);
}
public string ReadFile(string path, bool actualContent) {
if (!File.Exists(path))
return null;
@@ -29,6 +33,10 @@ namespace Orchard.Tests.Stubs {
throw new NotImplementedException();
}
public void CopyFileTo(string virtualPath, Stream destination, bool actualContent) {
throw new NotImplementedException();
}
public IVolatileToken WhenPathChanges(string path) {
return new Token {IsCurrent = true};
}

View File

@@ -11,7 +11,9 @@ namespace Orchard.FileSystems.WebSite {
bool FileExists(string virtualPath);
string ReadFile(string virtualPath);
string ReadFile(string virtualPath, bool actualContent);
void CopyFileTo(string virtualPath, Stream destination);
void CopyFileTo(string virtualPath, Stream destination, bool actualContent);
IVolatileToken WhenPathChanges(string virtualPath);
}

View File

@@ -9,10 +9,12 @@ using Orchard.FileSystems.VirtualPath;
namespace Orchard.FileSystems.WebSite {
public class WebSiteFolder : IWebSiteFolder {
private readonly IVirtualPathProvider _virtualPathProvider;
private readonly IVirtualPathMonitor _virtualPathMonitor;
public WebSiteFolder(IVirtualPathMonitor virtualPathMonitor) {
public WebSiteFolder(IVirtualPathMonitor virtualPathMonitor, IVirtualPathProvider virtualPathProvider) {
_virtualPathMonitor = virtualPathMonitor;
_virtualPathProvider = virtualPathProvider;
}
public IEnumerable<string> ListDirectories(string virtualPath) {
@@ -31,21 +33,52 @@ namespace Orchard.FileSystems.WebSite {
}
public string ReadFile(string virtualPath) {
return ReadFile(virtualPath, false);
}
public string ReadFile(string virtualPath, bool actualContent) {
if (!HostingEnvironment.VirtualPathProvider.FileExists(virtualPath))
return null;
if (actualContent) {
var physicalPath = _virtualPathProvider.MapPath(virtualPath);
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) {
CopyFileTo(virtualPath, destination, false/*actualContent*/);
}
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);
}
}
}
public IVolatileToken WhenPathChanges(string virtualPath) {
return _virtualPathMonitor.WhenPathChanges(virtualPath);

View File

@@ -141,7 +141,7 @@ namespace Orchard.Packaging {
var partUri = PackUriHelper.CreatePartUri(new Uri(context.TargetPath + relativePath, UriKind.Relative));
var packagePart = context.Package.CreatePart(partUri, contentType);
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;
}