chmod before trying to fix-shebangs if necessary

This commit is contained in:
Max Howell 2023-01-30 13:50:26 -05:00
parent 5c7531e66f
commit e0c0fddcb4
No known key found for this signature in database
GPG key ID: 741BB84EF5BB9EEC

View file

@ -66,5 +66,9 @@ for (const path of Deno.args) {
console.verbose({rewrote: path, to: `#!/usr/bin/env ${interpreter}`}) 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)) await Deno.writeFile(path, new TextEncoder().encode(rewrite))
if (needs_chmod) Deno.chmodSync(path, stat.mode!)
} }