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 <jhashivam2020@gmail.com>

# Conflicts:
#	bot/helper/ext_utils/fs_utils.py
This commit is contained in:
jaskaranSM 2020-02-02 14:48:23 +05:30 committed by lzzy12
parent 36df3aa2b4
commit afc2808acc

View File

@ -4,6 +4,7 @@ import shutil
import os import os
import pathlib import pathlib
import magic import magic
import tarfile
def clean_download(path: str): def clean_download(path: str):
@ -30,12 +31,14 @@ def exit_clean_up(signal, frame):
sys.exit(1) sys.exit(1)
def tar(orig_path: str): def tar(org_path):
path = pathlib.PurePath(orig_path) tar_path = org_path + ".tar"
base = path.name path = pathlib.PurePath(org_path)
root = pathlib.Path(path.parent.as_posix()).absolute().as_posix() LOGGER.info(f'Tar: orig_path: {org_path}, tar_path: {tar_path}')
LOGGER.info(f'Tar: orig_path: {orig_path}, base: {base}, root: {root}') tar = tarfile.open(tar_path, "w")
return shutil.make_archive(orig_path, 'tar', root, base) tar.add(org_path, arcname=path.name)
tar.close()
return tar_path
def get_mime_type(file_path): def get_mime_type(file_path):