commit:     fbf87aadee99356a0c9b281ca840c29213fb270a
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Wed Dec 10 11:16:37 2025 +0000
Commit:     Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Wed Dec 10 11:16:37 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=fbf87aad

chore: import snakeoil.tar so pkgcore usage can be removed at our pace

snakeoil.tar existed to fix upstream python issues in memory usage; those
were fixed somewhere in the early py3k days, but snakeoil also eventually
added support for the snakeoil.data_sources protocol, which also is going
to be deprecated and removed.

This tar module is moved here because pkgcore binpkgs is the only thing
that uses it, so migration away from that will be handled within pkgcore
itself.

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>

 src/pkgcore/fs/_tar.py | 28 ++++++++++++++++++++++++++++
 src/pkgcore/fs/tar.py  |  2 +-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/pkgcore/fs/_tar.py b/src/pkgcore/fs/_tar.py
new file mode 100644
index 00000000..92c53bd8
--- /dev/null
+++ b/src/pkgcore/fs/_tar.py
@@ -0,0 +1,28 @@
+"""This is internal, do not use it externally, nor add any further usage of it.
+
+This is a version of tarfile modified strictly for snakeoil.data_sources usage.
+
+This is will be removed once pkgcore and snakeoil data_source usage is removed.
+"""
+
+from snakeoil.python_namespaces import protect_imports
+
+
+# force a fresh module import of tarfile that is ours to monkey patch.
+with protect_imports() as (_paths, modules):
+    modules.pop("tarfile", None)
+    tarfile = __import__("tarfile")
+
+
+# add in a tweaked ExFileObject that is usable by snakeoil.data_source
+class ExFileObject(tarfile.ExFileObject):
+    __slots__ = ()
+    exceptions = (EnvironmentError,)
+
+
+tarfile.fileobject = ExFileObject
+
+# finished monkey patching. now to lift things out of our tarfile
+# module into this scope so from/import behaves properly.
+
+locals().update((k, getattr(tarfile, k)) for k in tarfile.__all__)

diff --git a/src/pkgcore/fs/tar.py b/src/pkgcore/fs/tar.py
index bdef5113..db57fd40 100644
--- a/src/pkgcore/fs/tar.py
+++ b/src/pkgcore/fs/tar.py
@@ -10,9 +10,9 @@ from itertools import count
 from snakeoil import compression
 from snakeoil.compatibility import cmp, sorted_cmp
 from snakeoil.data_source import invokable_data_source
-from snakeoil.tar import tarfile
 
 from . import contents
+from ._tar import tarfile
 from .fs import fsDev, fsDir, fsFifo, fsFile, fsSymlink
 
 _unique_inode = count(2**32).__next__

Reply via email to