Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
fixes #69 - ZipFile.ExtractToDirectory does not allow overwrite (#70)
Browse files Browse the repository at this point in the history
* fixes #69

* fixing code inspections

* fixing more code inspections, can't fix all though

* resharper weirdness
  • Loading branch information
yvesgoeleven authored and SeanFeldman committed Jan 17, 2017
1 parent 5851d99 commit e7f0844
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ static class AppDomainExtensions
public static T CreateInstanceAndUnwrap<T>(this AppDomain domain, params object[] args)
{
var type = typeof(T);
return (T)domain.CreateInstanceFromAndUnwrap(type.Assembly.Location, type.FullName, false, BindingFlags.Default, null, args, null, null);
var location = type.Assembly.Location;
return location != null ? (T)domain.CreateInstanceFromAndUnwrap(location, type.FullName, false, BindingFlags.Default, null, args, null, null) : default(T);
}
}
}
12 changes: 8 additions & 4 deletions src/NServiceBus.Hosting.Azure.Tests/APIApprovals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ public class APIApprovals
public void Approve()
{
Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
var assemblyPath = Path.GetFullPath(typeof(GenericHost).Assembly.Location);
var asm = AssemblyDefinition.ReadAssembly(assemblyPath);
var publicApi = Filter(PublicApiGenerator.CreatePublicApiForAssembly(asm));
Approvals.Verify(publicApi);
var location = typeof(GenericHost).Assembly.Location;
if (location != null)
{
var assemblyPath = Path.GetFullPath(location);
var asm = AssemblyDefinition.ReadAssembly(assemblyPath);
var publicApi = Filter(PublicApiGenerator.CreatePublicApiForAssembly(asm));
Approvals.Verify(publicApi);
}
}

string Filter(string text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ public void Install(string username)
//todo -yves
}

public void UpdatedEndpoints(object sender, EndpointsEventArgs e)
void UpdatedEndpoints(object sender, EndpointsEventArgs e)
{
runner.Stop(e.Endpoints);
provisioner.Remove(e.Endpoints);
provisioner.Provision(e.Endpoints);
runner.Start(e.Endpoints);
}

public void NewEndpoints(object sender, EndpointsEventArgs e)
void NewEndpoints(object sender, EndpointsEventArgs e)
{
provisioner.Provision(e.Endpoints);
runner.Start(e.Endpoints);
monitor.Monitor(e.Endpoints);
runningServices.AddRange(e.Endpoints);
}

public void RemovedEndpoints(object sender, EndpointsEventArgs e)
void RemovedEndpoints(object sender, EndpointsEventArgs e)
{
monitor.StopMonitoring(e.Endpoints);
runner.Stop(e.Endpoints);
Expand Down
12 changes: 6 additions & 6 deletions src/NServiceBus.Hosting.Azure/DynamicHost/DynamicHostMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ class DynamicHostMonitor

public int Interval { get; set; }

public void OnUpdatedEndpoints(EndpointsEventArgs e)
void OnUpdatedEndpoints(EndpointsEventArgs e)
{
var handler = UpdatedEndpoints;
if (handler != null) handler(this, e);
handler?.Invoke(this, e);
}

public void OnNewEndpoints(EndpointsEventArgs e)
void OnNewEndpoints(EndpointsEventArgs e)
{
var handler = NewEndpoints;
if (handler != null) handler(this, e);
handler?.Invoke(this, e);
}

public void OnRemovedEndpoints(EndpointsEventArgs e)
void OnRemovedEndpoints(EndpointsEventArgs e)
{
var handler = RemovedEndpoints;
if (handler != null) handler(this, e);
handler?.Invoke(this, e);
}

public void Monitor(IEnumerable<EndpointToHost> hostedEndpoints)
Expand Down
24 changes: 21 additions & 3 deletions src/NServiceBus.Hosting.Azure/DynamicHost/EndpointToHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public EndpointToHost(CloudBlockBlob blob)
public int ProcessId { get; set; }

public DateTime LastUpdated { get; set; }



public void ExtractTo(string rootPath)
{
var localDirectory = Path.Combine(rootPath, EndpointName);
Expand All @@ -36,7 +35,26 @@ public void ExtractTo(string rootPath)
blob.DownloadToStream(fs);
}

ZipFile.ExtractToDirectory(localFileName, localDirectory);
using (var archive = ZipFile.OpenRead(localFileName))
{
foreach (var entry in archive.Entries)
{
var entryFullname = Path.Combine(localDirectory, entry.FullName);
var entryPath = Path.GetDirectoryName(entryFullname);
if (!Directory.Exists(entryPath))
{
// ReSharper disable once AssignNullToNotNullAttribute
Directory.CreateDirectory(entryPath);
}

var entryFileName = Path.GetFileName(entryFullname);
if (!string.IsNullOrEmpty(entryFileName))
{
entry.ExtractToFile(entryFullname, true);
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Services.Client" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
Expand Down

0 comments on commit e7f0844

Please sign in to comment.