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
32 changes: 28 additions & 4 deletions build/ExtractTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
/// <summary>A custom MSBuild task that extracts .zip archive files to a destination folder. This tasks uses
/// <see cref="ZipFile.ExtractToDirectory(string, string)"/> to extract the files, which ensures that Unix permissions
/// are correctly restored. The MSBuild Unzip task does not restore Unix permissions.</summary>
/// <remarks>The destination folder is replaced only once every archive is extracted into a sibling staging folder,
/// so it is either complete or absent.</remarks>
public class ExtractTask : Task
{
/// <summary>Gets or sets a <see cref="ITaskItem"/> with a destination folder path to unzip the files to.
/// </summary>
/// <summary>Gets or sets a <see cref="ITaskItem"/> with a destination folder path to unzip the files to. An
/// existing destination folder is replaced.</summary>
[Required]
public ITaskItem DestinationFolder { get; set; }

Expand All @@ -27,10 +29,32 @@ public class ExtractTask : Task
/// <returns>Returns whether or not the execution completed successfully.</returns>
public override bool Execute()
{
foreach (ITaskItem sourceFile in SourceFiles)
string destinationFolder =
DestinationFolder.ItemSpec.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
string stagingFolder = destinationFolder + ".extracting";

DeleteFolder(stagingFolder);
try
{
foreach (ITaskItem sourceFile in SourceFiles)
{
ZipFile.ExtractToDirectory(sourceFile.ItemSpec, stagingFolder);
}
DeleteFolder(destinationFolder);
Directory.Move(stagingFolder, destinationFolder);
}
finally
{
ZipFile.ExtractToDirectory(sourceFile.ItemSpec, DestinationFolder.ItemSpec);
DeleteFolder(stagingFolder);
}
return true;
}

private static void DeleteFolder(string path)
{
if (Directory.Exists(path))
{
Directory.Delete(path, recursive: true);
}
}
}
2 changes: 1 addition & 1 deletion src/IceRpc.Protobuf.Tools/IceRpc.Protobuf.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<ExtractTask
SourceFiles="$(MSBuildThisFileDirectory)obj/protoc-$(ProtobufVersion)-osx-aarch_64.zip"
DestinationFolder="$(MSBuildThisFileDirectory)obj/protoc-$(ProtobufVersion)-osx-aarch_64"
Condition="!Exists('$(MSBuildThisFileDirectory)obj/protoc-$(ProtobufVersion)-osx-aarch_64')" />
Condition="!Exists('$(MSBuildThisFileDirectory)obj/protoc-$(ProtobufVersion)-osx-aarch_64/bin/protoc')" />

<!-- Make protoc compiler writeable, otherwise Copy task fails when running inside a container -->
<Exec
Expand Down
2 changes: 1 addition & 1 deletion src/IceRpc.Slice.Tools/IceRpc.Slice.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<ExtractTask
SourceFiles="$(MSBuildThisFileDirectory)obj/slicec-$(SlicecVersion)-%(SlicecPlatform.Identity).zip"
DestinationFolder="$(MSBuildThisFileDirectory)obj/slicec-$(SlicecVersion)-%(SlicecPlatform.Identity)"
Condition="!Exists('$(MSBuildThisFileDirectory)obj/slicec-$(SlicecVersion)-%(SlicecPlatform.Identity)')" />
Condition="!Exists('$(MSBuildThisFileDirectory)obj/slicec-$(SlicecVersion)-%(SlicecPlatform.Identity)/%(SlicecPlatform.Exe)')" />

<!-- Copy binaries to the tools directory structure expected by the props file. -->
<Copy
Expand Down
Loading