Skip to content

Commit

Permalink
try zip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Sep 2, 2024
1 parent 8257f59 commit 00d0519
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/flame/code_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ defmodule FLAME.CodeSync do
end

def package_to_stream(%CodeSync{} = code) do
compressed = if code.compress, do: [:compressed], else: []
compress = if code.compress, do: [{:compress, :all}], else: []

verbose =
if code.verbose do
Expand All @@ -164,15 +164,9 @@ defmodule FLAME.CodeSync do

out_stream =
if code.changed_paths != [] do
out_path = Path.join([mfa(code.tmp_dir), "flame_parent_code_sync_#{code.id}.tar.gz"])
out_path = Path.join([mfa(code.tmp_dir), "flame_parent_code_sync_#{code.id}.zip"])
dirs = for path <- code.changed_paths, uniq: true, do: String.to_charlist(path)
{:ok, tar} = :erl_tar.open(out_path, [:write] ++ compressed)

for dir <- dirs,
do: :erl_tar.add(tar, dir, trim_leading_slash(dir), [:dereference | verbose])

:ok = :erl_tar.close(tar)

:zip.zip(String.to_charlist(out_path), dirs, compress ++ verbose)
File.stream!(out_path, [], code.chunk_size)
end

Expand All @@ -192,21 +186,22 @@ defmodule FLAME.CodeSync do
}
end

defp trim_leading_slash([?/ | path]), do: path
defp trim_leading_slash([_ | _] = path), do: path

def extract_packaged_stream(%PackagedStream{} = pkg) do
if pkg.stream do
verbose = if pkg.verbose, do: [:verbose], else: []
compressed = if pkg.compress, do: [:compressed], else: []
compressed = if pkg.compress, do: [{:uncompress, :all}], else: []
extract_dir = mfa(pkg.extract_dir)
target_tmp_path = Path.join([mfa(pkg.tmp_dir), "flame_child_code_sync_#{pkg.id}.tar.gz"])
target_tmp_path = Path.join([mfa(pkg.tmp_dir), "flame_child_code_sync_#{pkg.id}.zip"])
flame_stream = File.stream!(target_tmp_path)
# transfer the file
Enum.into(pkg.stream, flame_stream)

# extract tar
:ok = :erl_tar.extract(target_tmp_path, [{:cwd, extract_dir}] ++ compressed ++ verbose)
{:ok, _} =
:zip.unzip(
String.to_charlist(target_tmp_path),
[{:cwd, String.to_charlist(extract_dir)}] ++ compressed ++ verbose
)

# add code paths
:ok = add_code_paths_from_tar(pkg, extract_dir)
Expand Down

0 comments on commit 00d0519

Please sign in to comment.