From b314be0f6b483bb3b47e69c363e07d4eec45f041 Mon Sep 17 00:00:00 2001
From: Priyagupta108 <priyagupta108@github.com>
Date: Mon, 2 Sep 2024 15:38:24 +0530
Subject: [PATCH] Add condition to ensure ZIP extraction targets only Windows
 ARM64 official archives

---
 dist/setup/index.js                                  | 8 ++++----
 src/distributions/base-distribution.ts               | 7 ++++---
 src/distributions/official_builds/official_builds.ts | 6 +++++-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/dist/setup/index.js b/dist/setup/index.js
index 2e3e552a..e1b7296f 100644
--- a/dist/setup/index.js
+++ b/dist/setup/index.js
@@ -93883,7 +93883,7 @@ class BaseDistribution {
                 }
                 throw err;
             }
-            const toolPath = yield this.extractArchive(downloadPath, info);
+            const toolPath = yield this.extractArchive(downloadPath, info, true);
             core.info('Done');
             return toolPath;
         });
@@ -93933,7 +93933,7 @@ class BaseDistribution {
             return toolPath;
         });
     }
-    extractArchive(downloadPath, info) {
+    extractArchive(downloadPath, info, isOfficialArchive) {
         return __awaiter(this, void 0, void 0, function* () {
             //
             // Extract
@@ -93948,7 +93948,7 @@ class BaseDistribution {
                 // on Windows runners without PowerShell Core.
                 //
                 // For default PowerShell Windows it should contain extension type to unpack it.
-                if (extension === '.zip') {
+                if (extension === '.zip' && isOfficialArchive) {
                     const renamedArchive = `${downloadPath}.zip`;
                     fs_1.default.renameSync(downloadPath, renamedArchive);
                     extPath = yield tc.extractZip(renamedArchive);
@@ -94186,7 +94186,7 @@ class OfficialBuilds extends base_distribution_1.default {
                     core.info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
                     downloadPath = yield tc.downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
                     if (downloadPath) {
-                        toolPath = yield this.extractArchive(downloadPath, versionInfo);
+                        toolPath = yield this.extractArchive(downloadPath, versionInfo, false);
                     }
                 }
                 else {
diff --git a/src/distributions/base-distribution.ts b/src/distributions/base-distribution.ts
index cf5bb544..70b4b572 100644
--- a/src/distributions/base-distribution.ts
+++ b/src/distributions/base-distribution.ts
@@ -150,7 +150,7 @@ export default abstract class BaseDistribution {
       throw err;
     }
 
-    const toolPath = await this.extractArchive(downloadPath, info);
+    const toolPath = await this.extractArchive(downloadPath, info, true);
     core.info('Done');
 
     return toolPath;
@@ -210,7 +210,8 @@ export default abstract class BaseDistribution {
 
   protected async extractArchive(
     downloadPath: string,
-    info: INodeVersionInfo | null
+    info: INodeVersionInfo | null,
+    isOfficialArchive?: boolean
   ) {
     //
     // Extract
@@ -225,7 +226,7 @@ export default abstract class BaseDistribution {
       // on Windows runners without PowerShell Core.
       //
       // For default PowerShell Windows it should contain extension type to unpack it.
-      if (extension === '.zip') {
+      if (extension === '.zip' && isOfficialArchive) {
         const renamedArchive = `${downloadPath}.zip`;
         fs.renameSync(downloadPath, renamedArchive);
         extPath = await tc.extractZip(renamedArchive);
diff --git a/src/distributions/official_builds/official_builds.ts b/src/distributions/official_builds/official_builds.ts
index 4e368b00..e56eaf81 100644
--- a/src/distributions/official_builds/official_builds.ts
+++ b/src/distributions/official_builds/official_builds.ts
@@ -88,7 +88,11 @@ export default class OfficialBuilds extends BaseDistribution {
         );
 
         if (downloadPath) {
-          toolPath = await this.extractArchive(downloadPath, versionInfo);
+          toolPath = await this.extractArchive(
+            downloadPath,
+            versionInfo,
+            false
+          );
         }
       } else {
         core.info(