From afc2808accf86abb88f2ee7d3c4f3f5b7492384d Mon Sep 17 00:00:00 2001 From: jaskaranSM Date: Sun, 2 Feb 2020 14:48:23 +0530 Subject: [PATCH] Rewrite tar function - shutil changes pwd while archiving. as some functions of bot require relative paths, it is neccesary to keep pwd as bot root dir. Signed-off-by: lzzy12 # Conflicts: # bot/helper/ext_utils/fs_utils.py --- bot/helper/ext_utils/fs_utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bot/helper/ext_utils/fs_utils.py b/bot/helper/ext_utils/fs_utils.py index 1d0a7ed..019cc77 100644 --- a/bot/helper/ext_utils/fs_utils.py +++ b/bot/helper/ext_utils/fs_utils.py @@ -4,6 +4,7 @@ import shutil import os import pathlib import magic +import tarfile def clean_download(path: str): @@ -30,12 +31,14 @@ def exit_clean_up(signal, frame): sys.exit(1) -def tar(orig_path: str): - path = pathlib.PurePath(orig_path) - base = path.name - root = pathlib.Path(path.parent.as_posix()).absolute().as_posix() - LOGGER.info(f'Tar: orig_path: {orig_path}, base: {base}, root: {root}') - return shutil.make_archive(orig_path, 'tar', root, base) +def tar(org_path): + tar_path = org_path + ".tar" + path = pathlib.PurePath(org_path) + LOGGER.info(f'Tar: orig_path: {org_path}, tar_path: {tar_path}') + tar = tarfile.open(tar_path, "w") + tar.add(org_path, arcname=path.name) + tar.close() + return tar_path def get_mime_type(file_path):