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 <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
This commit is contained in:
Jan Lindemann 2026-11-03 11:18:34 +01:00
commit 4117143c05
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -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