From 612a443ddebb57dcbfb5b14043cc010bde6c7009 Mon Sep 17 00:00:00 2001 From: gluap Date: Fri, 12 May 2023 21:35:41 +0200 Subject: [PATCH] make the tar strip the common parts of the directory structure. --- api/obs/api/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/obs/api/utils.py b/api/obs/api/utils.py index 796e6e0..0e822b9 100644 --- a/api/obs/api/utils.py +++ b/api/obs/api/utils.py @@ -1,5 +1,6 @@ from datetime import datetime import logging +import os import queue import tarfile @@ -94,10 +95,14 @@ async def tar_of_tracks(req, files): helper = StreamerHelper(response) tar = tarfile.open(name=None, fileobj=helper, mode="w|bz2", bufsize=256 * 512) + + root = os.path.commonpath(list(files)) for fname in files: log.info("Write file to tar: %s", fname) with open(fname, "rb") as fobj: - tar.addfile(tar.gettarinfo(fname), fobj) + tarinfo = tar.gettarinfo(fname) + tarinfo.name = os.path.relpath(fname, root) + tar.addfile(tarinfo, fobj) await helper.send_all() tar.close() await helper.send_all()