Skip to content

Commit 73fed3e

Browse files
Make file writable before applying strip (#12)
Fixes elixir-desktop/desktop-example-app#31 The strip command modifies files in-place and fails with 'Permission denied' when files (e.g. .so NIF libraries) have read-only permissions. Ensure the file is writable with File.chmod! before running strip, matching the pattern already used in file_replace/3. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Dominic Letz <dominicletz@users.noreply.github.com>
1 parent eaa5760 commit 73fed3e

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/tooling.ex

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,17 @@ defmodule Desktop.Deployment.Tooling do
7676
is_binary = extname == ""
7777
is_library = Regex.match?(~r/\.(so|dylib|smp)($|\.)/, extname)
7878

79-
cond do
80-
os() == MacOS and is_library -> cmd!("strip", ["-x", "-S", file])
81-
os() == MacOS and is_binary -> cmd!("strip", ["-u", "-r", file])
82-
is_binary || is_library -> cmd!("strip", ["-s", file])
83-
true -> :ok
79+
strip_args =
80+
cond do
81+
os() == MacOS and is_library -> ["-x", "-S"]
82+
os() == MacOS and is_binary -> ["-u", "-r"]
83+
is_binary || is_library -> ["-s"]
84+
true -> nil
85+
end
86+
87+
if strip_args do
88+
File.chmod!(file, Bitwise.bor(File.lstat!(file).mode, 0o200))
89+
cmd!("strip", strip_args ++ [file])
8490
end
8591

8692
file

0 commit comments

Comments
 (0)