objectstore: support os.PathLike in Object.export
Support `os.PathLike` arguments in `Object.export` by explicitly converting the supplied argument via `os.fspath`. Additionally, declare the support for those via the Python typing system with a new Union type for general `PathLike` type, i.e. all valid types for `os.fspath`, which are `str`, `bytes`, `os.PathLike`.
This commit is contained in:
parent
8250bd0b94
commit
833a79ee6f
1 changed files with 8 additions and 4 deletions
|
|
@ -5,7 +5,7 @@ import os
|
|||
import subprocess
|
||||
import tempfile
|
||||
import weakref
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
from osbuild.util import ctx, rmrf
|
||||
from . import treesum
|
||||
|
|
@ -16,6 +16,10 @@ __all__ = [
|
|||
]
|
||||
|
||||
|
||||
# Type for valid inputs to `os.fspath`
|
||||
PathLike = Union[str, bytes, os.PathLike]
|
||||
|
||||
|
||||
def mount(source, target, bind=True, ro=True, private=True, mode="0755"):
|
||||
options = []
|
||||
if bind:
|
||||
|
|
@ -192,7 +196,7 @@ class Object:
|
|||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.cleanup()
|
||||
|
||||
def export(self, to_directory):
|
||||
def export(self, to_directory: PathLike):
|
||||
"""Copy object into an external directory"""
|
||||
with self.read() as from_directory:
|
||||
subprocess.run(
|
||||
|
|
@ -200,8 +204,8 @@ class Object:
|
|||
"cp",
|
||||
"--reflink=auto",
|
||||
"-a",
|
||||
f"{from_directory}/.",
|
||||
to_directory,
|
||||
os.fspath(from_directory) + "/.",
|
||||
os.fspath(to_directory),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue