Fix: File names URI unescape (aka %20). #414 #544 #603.

This commit is contained in:
Ran-Intendu
2016-04-05 16:55:20 +03:00
parent fca8876109
commit cd749332d1
4 changed files with 42 additions and 11 deletions

View File

@@ -128,7 +128,7 @@ namespace Squirrel
using (Utility.WithTempDirectory(out tempPath, null)) {
var tempDir = new DirectoryInfo(tempPath);
extractZipDecoded(InputPackageFile, tempPath);
ExtractZipDecoded(InputPackageFile, tempPath);
this.Log().Info("Extracting dependent packages: [{0}]", String.Join(",", dependencies.Select(x => x.Id)));
extractDependentPackages(dependencies, tempDir, targetFramework);
@@ -158,7 +158,7 @@ namespace Squirrel
// nupkg file %-encodes zip entry names. This method decodes entry names before writing to disk.
// We must do this, or PathTooLongException may be thrown for some unicode entry names.
void extractZipDecoded(string zipFilePath, string outFolder)
public static void ExtractZipDecoded(string zipFilePath, string outFolder, string directoryFilter = null)
{
var zf = new ZipFile(zipFilePath);
@@ -172,12 +172,15 @@ namespace Squirrel
var fullZipToPath = Path.Combine(outFolder, entryFileName);
var directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0) {
Directory.CreateDirectory(directoryName);
}
var directoryFilter_ = new NameFilter(directoryFilter);
if (directoryFilter_.IsMatch(directoryName)) {
if (directoryName.Length > 0) {
Directory.CreateDirectory(directoryName);
}
using (FileStream streamWriter = File.Create(fullZipToPath)) {
StreamUtils.Copy(zipStream, streamWriter, buffer);
using (FileStream streamWriter = File.Create(fullZipToPath)) {
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
zf.Close();

View File

@@ -289,7 +289,6 @@ namespace Squirrel
Task<string> installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release)
{
return Task.Run(async () => {
var zipper = new FastZip();
var target = getDirectoryForRelease(release.Version);
// NB: This might happen if we got killed partially through applying the release
@@ -301,9 +300,8 @@ namespace Squirrel
target.Create();
this.Log().Info("Writing files to app directory: {0}", target.FullName);
zipper.ExtractZip(
Path.Combine(updateInfo.PackageDirectory, release.Filename),
target.FullName, FastZip.Overwrite.Always, (o) => true, null, @"lib", true);
ReleasePackage.ExtractZipDecoded(Path.Combine(updateInfo.PackageDirectory, release.Filename),
target.FullName, @"lib");
// Move all of the files out of the lib/ dirs in the NuGet package
// into our target App directory.

View File

@@ -111,6 +111,36 @@ namespace Squirrel.Tests
}
}
[Fact]
public async Task SpecialCharactersInitialInstallTest()
{
string tempDir;
using (Utility.WithTempDirectory(out tempDir))
{
var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
var localAppDir = Path.Combine(tempDir, "theApp");
new[] {
"SpecialCharacters-0.1.0-full.nupkg",
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
using (var fixture = new UpdateManager(remotePackageDir.FullName, "theApp", tempDir))
{
await fixture.FullInstall();
}
var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
File.Exists(releasePath).ShouldBeTrue();
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
entries.Count().ShouldEqual(1);
new[] {
"file space name.txt"
}.ForEach(x => File.Exists(Path.Combine(localAppDir, "app-0.1.0", x)).ShouldBeTrue());
}
}
[Fact]
public async Task WhenBothFilesAreInSyncNoUpdatesAreApplied()
{

Binary file not shown.