Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"ms-vscode.csharp",
"ms-vscode.cpptools",
"ms-vscode.mono-debug",
"wghats.vscode-nxunit-test-adapter",
"visualstudioexptteam.vscodeintellicode",
]
}
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "mono",
"request": "launch",
"program": "~/.nuget/packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe ${workspaceRoot}LibZipSharp.UnitTest/bin/Debug/net471/LibZipSharp.UnitTest.dll",
"cwd": "${workspaceRoot}bin/TestDebug/"
},
{
"name": "Attach",
"type": "mono",
"request": "attach",
"address": "localhost",
"port": 55555
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"nxunitExplorer.nunit": "/Users/dean/.nuget/packages/nunit.consolerunner/3.10.0/tools/nunit3-console.exe",
"nxunitExplorer.modules": [
"LibZipSharp.UnitTest/bin/Debug/net471/LibZipSharp.UnitTest.dll",
]
}
67 changes: 67 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build LibZipSharp",
"type": "shell",
"command": "msbuild LibZipSharp.csproj /restore /t:Build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "Pack LibZipSharp Nuget",
"type": "shell",
"command": "msbuild LibZipSharp.csproj /t:Pack",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "Clean LibZipSharp",
"type": "shell",
"command": "msbuild LibZipSharp.csproj /restore /t:Clean",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "Build LibZipSharp Unit Tests",
"type": "shell",
"command": "msbuild LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj /restore /t:Build /p:ReferenceNuget=False",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
},
{
"label": "Run LibZipSharp Unit Tests",
"type": "shell",
"command": "msbuild LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj /restore /t:RunNunitTests /p:ReferenceNuget=False",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [
"$msCompile"
]
}
]
}
21 changes: 17 additions & 4 deletions LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(MSBuildThisFileDirectory)..\LibZipSharp.props" />
<PropertyGroup>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFramework>net471</TargetFramework>

<IsPackable>false</IsPackable>
<LibZipSharpBundleAllNativeLibraries>true</LibZipSharpBundleAllNativeLibraries>
<ReferenceNuget Condition="'$(ReferenceNuget)' == ''">False</ReferenceNuget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Xamarin.LibZipSharp" Version="$(_LibZipSharpNugetVersion)" />
<PackageReference Include="Xamarin.LibZipSharp" Version="$(_LibZipSharpNugetVersion)" Condition="'$(ReferenceNuget)' == 'True'" />
<PackageReference Include="NUnit.ConsoleRunner" Version="3.10.0" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\libZipSharp.csproj" Condition="'$(ReferenceNuget)' != 'True'" />
<None Include="..\build\Darwin\64\lib\libzip.5.0.dylib" Condition="'$(ReferenceNuget)' != 'True'">
<Link>libzip.dylib</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\build\Windows\64\lib\libzip.dll" Condition="'$(ReferenceNuget)' != 'True'">
<Link>libzip.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="RunNunitTests" DependsOnTargets="Build">
<PropertyGroup>
<Host Condition="'$(OS)' != 'Windows_NT'">mono </Host>
</PropertyGroup>
<Exec Command="$(Host)$(NuGetPackageRoot)nunit.consolerunner/3.10.0/tools/nunit3-console.exe LibZipSharp.UnitTest.dll"
WorkingDirectory="$(OutputPath)\net45"
WorkingDirectory="$(OutputPath)"
/>
</Target>
</Project>
45 changes: 45 additions & 0 deletions LibZipSharp.UnitTest/ZipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.IO;
using System.Text;
using System.Threading;
using Xamarin.Tools.Zip;

namespace Tests {
Expand Down Expand Up @@ -70,5 +71,49 @@ public void CanExtractZipFile ()
FileAssert.AreEqual (Path.Combine (root, "in", "archive", "foo", "foo1.txt"), "foo1.txt", $"foo1.txt should have been {TEXT}");
}
}

static DateTime WithoutMilliseconds (DateTime t) =>
new DateTime (t.Year, t.Month, t.Day, t.Hour, t.Minute, t.Second, t.Kind);

[Test]
[Repeat (100)]
[NonParallelizable]
public void CheckDates ()
{
string root = Path.Combine (Path.GetDirectoryName (typeof (ZipTests).Assembly.Location));
string file = Path.Combine (root, "foo.txt");
string zip = Path.Combine (root, "foo.zip");
if (File.Exists (zip))
File.Delete (zip);
if (File.Exists (file))
File.Delete (file);
File.WriteAllText (file, TEXT);
DateTime lastWrite = WithoutMilliseconds (File.GetLastWriteTimeUtc (file));
Thread.Sleep (TimeSpan.FromSeconds (2));
using (var archive = ZipArchive.Open (zip, FileMode.Create)) {
var entry = archive.AddFile (file, archivePath: "foo.txt");
Assert.GreaterOrEqual (WithoutMilliseconds (entry.ModificationTime), lastWrite, $"Check 1 {WithoutMilliseconds (entry.ModificationTime)} < {lastWrite}");
}
using (var archive = ZipArchive.Open (zip, FileMode.Open)) {
ZipEntry entry = archive.ReadEntry ("foo.txt");
Assert.GreaterOrEqual (WithoutMilliseconds (entry.ModificationTime), lastWrite, $"Check 2 {WithoutMilliseconds (entry.ModificationTime)} < {lastWrite}");
}
}

[Test]
public void DateTimeConversion ()
{
DateTime now = DateTime.UtcNow;
for (int m = 0; m < 59; m++)
for (int s = 0; s < 59; s++)
for (int ms = 0; ms < 999; ms++) {
DateTime dt = new DateTime (now.Year, now.Month, now.Day, now.Hour, m, s, ms, DateTimeKind.Utc);
var dateTimeOffset = new DateTimeOffset(dt);
var unixTime = (ulong)dateTimeOffset.ToUnixTimeSeconds();
DateTime c = DateTimeOffset.FromUnixTimeSeconds ((long)unixTime).UtcDateTime;
Assert.AreEqual (WithoutMilliseconds (dt), WithoutMilliseconds (c));

}
}
}
}
8 changes: 8 additions & 0 deletions LibZipSharp.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
3 changes: 3 additions & 0 deletions Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ public static int zip_set_file_comment (IntPtr archive, UInt64 index, string com

[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int zip_set_file_compression (IntPtr archive, UInt64 index, CompressionMethod comp, UInt32 comp_flags);

[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int zip_file_set_mtime(IntPtr archive, UInt64 index, ulong mtime, UInt32 flags);

[DllImport (ZIP_LIBNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr zip_source_buffer (IntPtr archive, byte[] data, UInt64 len, int freep);
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.LibZipSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<LibZipSharpBundleAllNativeLibraries Condition=" '$(LibZipSharpBundleAllNativeLibraries)' == '' ">false</LibZipSharpBundleAllNativeLibraries>
</PropertyGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\lib\net45\libZipSharp.dll.config">
<None Include="$(MSBuildThisFileDirectory)..\lib\netstandard2.0\libZipSharp.dll.config">
<Link>libZipSharp.dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
4 changes: 2 additions & 2 deletions ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ public ZipEntry AddStream (Stream stream, string archivePath, EntryPermissions p
throw GetErrorException ();
if (Native.zip_set_file_compression (archive, (ulong)index, compressionMethod, 0) < 0)
throw GetErrorException ();

if (permissions == EntryPermissions.Default)
permissions = DefaultFilePermissions;
PlatformServices.Instance.SetEntryPermissions (this, (ulong)index, permissions, false);
Expand Down Expand Up @@ -721,7 +720,8 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
return -1;
var stat = Native.ZipSourceGetArgs<Native.zip_stat_t> (data, len);
stat.size = (UInt64)stream.Length;
stat.valid |= (ulong)StatFlags.Size;
stat.mtime = new IntPtr ((long)Utilities.UnixTimeFromDateTime (DateTime.UtcNow));
stat.valid |= (ulong)(StatFlags.Size | StatFlags.MTime);
Marshal.StructureToPtr (stat, data, false);
return (Int64)sizeof (Native.zip_stat_t);

Expand Down
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ stages:
inputs:
solution: libZipSharp.csproj
configuration: Release
msbuildArguments: /restore
msbuildArguments: /restore /v:diag
- task: MSBuild@1
displayName: NuGet pack libZipSharp
inputs:
Expand Down Expand Up @@ -133,7 +133,7 @@ stages:
inputs:
solution: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
configuration: Release
msbuildArguments: /restore /t:RunNunitTests
msbuildArguments: /restore /t:RunNunitTests /p:ReferenceNuget=True /v:diag
- job: testmacos
displayName: 'Test MacOS'
pool:
Expand All @@ -149,7 +149,7 @@ stages:
inputs:
solution: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
configuration: Release
msbuildArguments: /restore /t:RunNunitTests
msbuildArguments: /restore /t:RunNunitTests /p:ReferenceNuget=True /v:diag
- job: testwindows
displayName: 'Test Windows'
pool:
Expand All @@ -165,7 +165,7 @@ stages:
inputs:
solution: LibZipSharp.UnitTest/LibZipSharp.UnitTest.csproj
configuration: Release
msbuildArguments: /restore /t:RunNunitTests
msbuildArguments: /restore /t:RunNunitTests /p:ReferenceNuget=True /v:diag
- stage: Publish
dependsOn: Test
condition: eq(variables['System.TeamProject'], 'devdiv') # only sign the packages when running on Windows, and using the private server which has the certificates
Expand Down
6 changes: 3 additions & 3 deletions libZipSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<AssemblyName>libZipSharp</AssemblyName>
<AssemblyTitle>libZipSharp</AssemblyTitle>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Deterministic>false</Deterministic>
Expand Down Expand Up @@ -35,11 +35,11 @@
</PropertyGroup>
<ItemGroup>
<None Include="Xamarin.LibZipSharp.targets" PackagePath="build" Pack="true" />
<None Include="libZipSharp.dll.config" PackagePath="lib\net45" Pack="true">
<None Include="libZipSharp.dll.config" PackagePath="lib\netstandard2.0" Pack="true">
<Link>libZipSharp.dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="libZipSharp.dll.config" PackagePath="lib\netstandard2.0" Pack="true">
<None Include="libZipSharp.dll.config" PackagePath="lib\net45" Pack="true">
<Link>libZipSharp.dll.config</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down