Skip to content

Commit 496e7c1

Browse files
Pedro Piñera Buendíaclaude
authored andcommitted
fix: Group tar -C by parent directory to include all app dirs
When multiple app dirs share the same parent (e.g. all under _build/test/lib/), repeated `-C parent basename` pairs caused tar to only include the last one. Group by parent and pass all basenames after a single -C to fix. Also filter out the "." relative path entry. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2ab55e6 commit 496e7c1

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/terrarium/runtime.ex

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,28 @@ defmodule Terrarium.Runtime do
197197
String.starts_with?(p, otp_lib) or String.starts_with?(p, elixir_lib)
198198
end)
199199

200-
# Deploy entire app directories (app-version/) to preserve the ebin/priv structure.
201-
# This allows Application.app_dir/1 to find priv/ directories on the remote.
200+
# Deploy entire app directories to preserve the ebin/priv structure.
201+
# Group by parent directory so each -C is followed by all its basenames,
202+
# avoiding the issue where repeated -C to the same parent causes tar to
203+
# only include the last basename.
202204
app_dirs =
203205
ebin_paths
204206
|> Enum.map(&Path.dirname/1)
207+
|> Enum.reject(&(&1 == "."))
205208
|> Enum.uniq()
206209

210+
grouped =
211+
app_dirs
212+
|> Enum.group_by(&Path.dirname/1, &Path.basename/1)
213+
207214
Logger.debug("Creating tarball from #{length(app_dirs)} app dirs", sandbox_id: sandbox.id)
208215

209216
tarball_path = Path.join(System.tmp_dir!(), "terrarium_deploy_#{System.unique_integer([:positive])}.tar.gz")
210-
file_args = Enum.flat_map(app_dirs, fn dir -> ["-C", Path.dirname(dir), Path.basename(dir)] end)
217+
218+
file_args =
219+
Enum.flat_map(grouped, fn {parent, basenames} ->
220+
["-C", parent | basenames]
221+
end)
211222

212223
try do
213224
case System.cmd("tar", ["czf", tarball_path | file_args], stderr_to_stdout: true) do

0 commit comments

Comments
 (0)