Skip to content

Commit

Permalink
Tar: Allow skip-old-files option
Browse files Browse the repository at this point in the history
When running Wget.get(..., force_run=False) and Tar.extract it is
useful to allow Tar to skip extracting existing files on the second
pass.

Allow the skip-old-files option, so Tar.extract will not overwrite
existing files in the output directory.

Note: it's important to not use this option if you are providing LISA
with a default filename for your tarballs. This option could silently
allow Tar.extract to not update the contents of a directory with the
newer file contents.

I don't see anyone using that schema now. My apologies to future devs who
find this commit message while debugging that issue.
  • Loading branch information
mcgov committed Nov 12, 2024
1 parent fd74060 commit 2c8bc82
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lisa/tools/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def extract(
gzip: bool = False,
sudo: bool = False,
raise_error: bool = True,
skip_old_files: bool = False,
) -> None:
# create folder when it doesn't exist
assert_that(strip_components).described_as(
Expand All @@ -48,6 +49,21 @@ def extract(
if strip_components:
# optionally strip N top level components from a tar file
tar_cmd += f" --strip-components={strip_components}"

if skip_old_files:
# NOTE:
# This option is for when you are using
# Wget.get(..., force_run=False)
#
# Do not use this option if:
# - You may need to extract multiple versions of a
# given tarball on a node
# - You have provided a default output filename to Wget.get
# to fetch the tarball
#
# This skip-old-files option could silently skip extracting
# the second version of the tarball.
tar_cmd += " --skip-old-files"
result = self.run(tar_cmd, shell=True, force_run=True, sudo=sudo)
if raise_error:
result.assert_exit_code(
Expand Down

0 comments on commit 2c8bc82

Please sign in to comment.