aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvturov <vturov@yandex-team.com>2024-04-23 18:28:19 +0300
committervturov <vturov@yandex-team.com>2024-04-23 18:38:25 +0300
commit23fa83f57d604e18c1cae1e2ebecc2ccf46dd7c6 (patch)
tree2de0e6b5197a1a18381e12820daf0325ec9a71e6
parent672634a3a4bcac724e710a175f57743d1a67aecd (diff)
downloadydb-23fa83f57d604e18c1cae1e2ebecc2ccf46dd7c6.tar.gz
Отказаться от tarfile в пользу archive
2613c273019f722f1204406c28ef0d2fd7d1ab22
-rw-r--r--build/plugins/lib/nots/package_manager/base/node_modules_bundler.py56
-rw-r--r--build/plugins/lib/nots/package_manager/base/ya.make1
2 files changed, 27 insertions, 30 deletions
diff --git a/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py b/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py
index c632ecb24a..3a1d7213d1 100644
--- a/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py
+++ b/build/plugins/lib/nots/package_manager/base/node_modules_bundler.py
@@ -1,9 +1,5 @@
import os
-import sys
-import subprocess
-import tarfile
-
-from io import BytesIO
+import tempfile
from .utils import build_nm_path
@@ -25,24 +21,30 @@ def bundle_node_modules(build_root, peers, node_modules_path, bundle_path):
:param bundle_path: tarball path
:type bundle_path: str
"""
- with tarfile.open(bundle_path, "w") as tf:
- tf.add(node_modules_path, arcname=".")
+ import library.python.archive as archive
- # Peers' node_modules.
- added_peers = []
- for p in peers:
- peer_nm_path = build_nm_path(os.path.join(build_root, p))
- peer_bundled_nm_path = build_nm_path(os.path.join(PEERS_DIR, p))
- if not os.path.isdir(peer_nm_path):
- continue
- tf.add(peer_nm_path, arcname=peer_bundled_nm_path)
- added_peers.append(p)
+ paths_to_pack = []
+ paths_to_pack.append((node_modules_path, "."))
+
+ # Peers' node_modules.
+ added_peers = []
+ for p in peers:
+ peer_nm_path = build_nm_path(os.path.join(build_root, p))
+ peer_bundled_nm_path = build_nm_path(os.path.join(PEERS_DIR, p))
+ if not os.path.isdir(peer_nm_path):
+ continue
+ paths_to_pack.append((peer_nm_path, peer_bundled_nm_path))
+ added_peers.append(p)
- # Peers index.
- peers_index = "\n".join(added_peers)
- ti = tarfile.TarInfo(name=os.path.join(PEERS_DIR, PEERS_INDEX))
- ti.size = len(peers_index)
- tf.addfile(ti, BytesIO(peers_index.encode()))
+ # Peers index.
+ with tempfile.TemporaryDirectory() as temp_dir:
+ peers_index_tmppath = os.path.join(temp_dir, PEERS_INDEX)
+ peers_index_relpath = os.path.join(PEERS_DIR, PEERS_INDEX)
+ with open(peers_index_tmppath, "w") as peers_index:
+ peers_index.write("\n".join(added_peers))
+ paths_to_pack.append((peers_index_tmppath, peers_index_relpath))
+
+ archive.tar(paths_to_pack, bundle_path, compression_filter=None, compression_level=None, fixed_mtime=0)
def extract_node_modules(build_root, node_modules_path, bundle_path):
@@ -55,16 +57,10 @@ def extract_node_modules(build_root, node_modules_path, bundle_path):
:param bundle_path: tarball path
:type bundle_path: str
"""
- os.makedirs(node_modules_path, exist_ok=True)
- tar_unpack_cmd = ["tar", "xf", bundle_path, "-C", node_modules_path]
- p = subprocess.run(tar_unpack_cmd, capture_output=True, text=True)
- if p.returncode != 0:
- if p.stdout:
- sys.stderr.write(f"stdout:\n{p.stdout}\n")
- if p.stderr:
- sys.stderr.write(f"stderr:\n{p.stderr}\n")
+ import library.python.archive as archive
- return False
+ os.makedirs(node_modules_path, exist_ok=True)
+ archive.extract_tar(bundle_path, node_modules_path, fail_on_duplicates=False)
with open(os.path.join(node_modules_path, PEERS_DIR, PEERS_INDEX)) as peers_file:
peers = peers_file.read().split("\n")
diff --git a/build/plugins/lib/nots/package_manager/base/ya.make b/build/plugins/lib/nots/package_manager/base/ya.make
index d377a48cf4..807cee2ca6 100644
--- a/build/plugins/lib/nots/package_manager/base/ya.make
+++ b/build/plugins/lib/nots/package_manager/base/ya.make
@@ -16,6 +16,7 @@ PY_SRCS(
PEERDIR(
contrib/python/six
+ library/python/archive
)
END()