Skip to content

Commit

Permalink
https://github.com/rpm-software-management/tito/issues/414
Browse files Browse the repository at this point in the history
  • Loading branch information
belonesox committed Dec 18, 2021
1 parent e58d7ca commit 7abc001
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/tito/builder/submodule_aware_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def run_git_archive(self, relative_git_dir, prefix, commit, dest_tar, subdir):
if not subdir:
subdir = os.getcwd()

from pathlib import Path
Path(dest_tar).parent.mkdir( parents=True, exist_ok=True )

with chdir(subdir) as p:
run_command(git_archive_cmd)

Expand Down Expand Up @@ -141,12 +144,24 @@ def create_tgz(self, git_root, prefix, commit, relative_dir,

# we need to append all of the submodule tar files onto the initial
tarfiles = ' '.join(submodule_tar_files)
run_command("tar -Af %s" % tarfiles)
scmd = f"tar -n --concatenate --file {tarfiles}"
run_command(scmd)

initial_tar_dir = initial_tar + '.dir'
os.mkdir(initial_tar_dir)
initial_tar_fixed = initial_tar + '.fixed'
scmd = f'tar -ixf {initial_tar} -C {initial_tar_dir}'
run_command(scmd)
scmd = f'tar cf {initial_tar_fixed} -C {initial_tar_dir} {prefix}'
run_command(scmd)

# Sorry, I failed to write reliable oneliner to repack/fix incorrect tar with zeros, without unpacking to files on FS. Hope such magic line exists.
# scmd = f'tar -xif {initial_tar} | tar -cf {initial_tar_fixed} --warning=no-file-changed --warning=no-file-removed -T - '

fixed_tar = "%s.tar" % basename
fixed_tar_fh = open(fixed_tar, 'wb')
try:
tarfixer = TarFixer(open(initial_tar, 'rb'), fixed_tar_fh, timestamp, commit)
tarfixer = TarFixer(open(initial_tar_fixed, 'rb'), fixed_tar_fh, timestamp, commit)
tarfixer.fix()
finally:
fixed_tar_fh.close()
Expand Down
7 changes: 5 additions & 2 deletions src/tito/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,11 @@ def process_chunk(self, chunk):

for member in self.octal_members:
# Convert octals to decimal
chunk_props[member] = int(chunk_props[member], 8)

if chunk_props[member]: # devmajors can be empty
chunk_props[member] = int(chunk_props[member], 8)
else:
chunk_props[member] = 0

# If there is no global header, we need to create one
if self.need_header:
# When run against a tree ID, git archive doesn't create
Expand Down

0 comments on commit 7abc001

Please sign in to comment.