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 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):