Skip to content

Commit

Permalink
Deal with symlinks in generated embeddings
Browse files Browse the repository at this point in the history
Summary:
When embedding files into the redex Python environment, the Python `tarfile` support will create symlinks when the inputs are symlinks. That, of course, defeats the purpose.

Use `TarInfo` construction that avoids the issue.

Reviewed By: IanChilds

Differential Revision: D41507787

fbshipit-source-id: e72041d5d82e3166b23cd8deb1e9cea445173c2b
  • Loading branch information
agampe authored and facebook-github-bot committed Nov 23, 2022
1 parent cfdd00d commit 41d5dc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions gen_packed_apilevels.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def compress_tar_xz(inputs):

for input in inputs:
logging.info("Adding %s", input)
info = tar.gettarinfo(input)
info.name = os.path.basename(input)
# In case the inputs are symlinks, it's better to work with the file
# object outright.
with open(input, "rb") as f:
info = tar.gettarinfo(arcname=os.path.basename(input), fileobj=f)
tar.addfile(info, fileobj=f)

tar.close()
Expand Down
5 changes: 3 additions & 2 deletions gen_simple_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def compress_tar_xz(inputs):

for input in inputs:
logging.info("Adding %s", input)
info = tar.gettarinfo(input)
info.name = os.path.basename(input)
# In case the inputs are symlinks, it's better to work with the file
# object outright.
with open(input, "rb") as f:
info = tar.gettarinfo(arcname=os.path.basename(input), fileobj=f)
tar.addfile(info, fileobj=f)

tar.close()
Expand Down

0 comments on commit 41d5dc8

Please sign in to comment.