From e0c0fddcb4fda5c420d5833bc833ecd05459f1ce Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 30 Jan 2023 13:50:26 -0500 Subject: [PATCH] chmod before trying to fix-shebangs if necessary --- scripts/brewkit/fix-shebangs.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/brewkit/fix-shebangs.ts b/scripts/brewkit/fix-shebangs.ts index 725d532d..8fbf78a8 100755 --- a/scripts/brewkit/fix-shebangs.ts +++ b/scripts/brewkit/fix-shebangs.ts @@ -66,5 +66,9 @@ for (const path of Deno.args) { console.verbose({rewrote: path, to: `#!/usr/bin/env ${interpreter}`}) + const stat = Deno.lstatSync(path) + const needs_chmod = stat.mode && !(stat.mode & 0o200) + if (needs_chmod) Deno.chmodSync(path, 0o666) await Deno.writeFile(path, new TextEncoder().encode(rewrite)) + if (needs_chmod) Deno.chmodSync(path, stat.mode!) }