From 4117143c051dc6c4712efac36ebb417668d92ae1 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 3 Nov 2026 11:18:34 +0100 Subject: [PATCH] lib.CopyContext: Add optional default_path_filter CopyContext creates its src and dst contexts from URIs when they are not given as instances. Pass an optional default_path_filter into that creation, so a copy made under a filter limits the addresses it reads and writes. A context given as an instance keeps the filter it already carries. Signed-off-by: Jan Lindemann Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0 --- src/python/jw/pkg/lib/CopyContext.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/python/jw/pkg/lib/CopyContext.py b/src/python/jw/pkg/lib/CopyContext.py index 3690d7b7..649a9614 100644 --- a/src/python/jw/pkg/lib/CopyContext.py +++ b/src/python/jw/pkg/lib/CopyContext.py @@ -1,8 +1,13 @@ -from typing import Any, Self +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Self from .FileContext import FileContext from .Uri import Uri +if TYPE_CHECKING: + from .PathFilter import PathFilter + class CopyContext: def __init__( @@ -10,6 +15,7 @@ class CopyContext: src: Uri | str | FileContext, dst: Uri | str | FileContext, chroot: bool = False, + default_path_filter: str | PathFilter | None = None, ) -> None: def __uri(ctx: FileContext | Uri | str) -> Uri | str: @@ -29,17 +35,26 @@ class CopyContext: self.__src, self.__src_uri = __info(src) self.__dst, self.__dst_uri = __info(dst) self.__chroot = chroot + self.__default_path_filter = default_path_filter async def __aenter__(self) -> Self: if self.__src is None: if self.__src_uri is None: raise Exception('Tried to create source context without URI') - self.__src = FileContext.create(self.__src_uri, chroot = self.__chroot) + self.__src = FileContext.create( + self.__src_uri, + chroot = self.__chroot, + default_path_filter = self.__default_path_filter, + ) await self.__src.open() if self.__dst is None: if self.__dst_uri is None: raise Exception('Tried to create destination context without URI') - self.__dst = FileContext.create(self.__dst_uri, chroot = self.__chroot) + self.__dst = FileContext.create( + self.__dst_uri, + chroot = self.__chroot, + default_path_filter = self.__default_path_filter, + ) await self.__dst.open() return self