Bläddra i källkod

Extract `ChunkerFixed` into a dedicated module under `chunkers`.

Moved the `ChunkerFixed` implementation from `chunker` to a new `fixed` module for better modularity. Updated imports and type hints.

Removed now empty chunkers.chunker module.
Thomas Waldmann 2 dagar sedan
förälder
incheckning
f44b1742f5

+ 0 - 1
.gitignore

@@ -7,7 +7,6 @@ src/borg/compress.c
 src/borg/crypto/low_level.c
 src/borg/crypto/low_level.c
 src/borg/item.c
 src/borg/item.c
 src/borg/chunkers/buzhash.c
 src/borg/chunkers/buzhash.c
-src/borg/chunkers/chunker.c
 src/borg/chunkers/reader.c
 src/borg/chunkers/reader.c
 src/borg/checksums.c
 src/borg/checksums.c
 src/borg/platform/darwin.c
 src/borg/platform/darwin.c

+ 0 - 1
scripts/make.py

@@ -543,7 +543,6 @@ cython_sources = """
 src/borg/compress.pyx
 src/borg/compress.pyx
 src/borg/crypto/low_level.pyx
 src/borg/crypto/low_level.pyx
 src/borg/chunkers/buzhash.pyx
 src/borg/chunkers/buzhash.pyx
-src/borg/chunkers/chunker.pyx
 src/borg/chunkers/reader.pyx
 src/borg/chunkers/reader.pyx
 src/borg/hashindex.pyx
 src/borg/hashindex.pyx
 src/borg/item.pyx
 src/borg/item.pyx

+ 0 - 3
setup.py

@@ -51,7 +51,6 @@ cflags = ["-Wall", "-Wextra", "-Wpointer-arith", "-Wno-unreachable-code-fallthro
 compress_source = "src/borg/compress.pyx"
 compress_source = "src/borg/compress.pyx"
 crypto_ll_source = "src/borg/crypto/low_level.pyx"
 crypto_ll_source = "src/borg/crypto/low_level.pyx"
 buzhash_source = "src/borg/chunkers/buzhash.pyx"
 buzhash_source = "src/borg/chunkers/buzhash.pyx"
-chunker_source = "src/borg/chunkers/chunker.pyx"
 reader_source = "src/borg/chunkers/reader.pyx"
 reader_source = "src/borg/chunkers/reader.pyx"
 hashindex_source = "src/borg/hashindex.pyx"
 hashindex_source = "src/borg/hashindex.pyx"
 item_source = "src/borg/item.pyx"
 item_source = "src/borg/item.pyx"
@@ -67,7 +66,6 @@ cython_sources = [
     compress_source,
     compress_source,
     crypto_ll_source,
     crypto_ll_source,
     buzhash_source,
     buzhash_source,
-    chunker_source,
     reader_source,
     reader_source,
     hashindex_source,
     hashindex_source,
     item_source,
     item_source,
@@ -187,7 +185,6 @@ if not on_rtd:
         Extension("borg.hashindex", [hashindex_source], extra_compile_args=cflags),
         Extension("borg.hashindex", [hashindex_source], extra_compile_args=cflags),
         Extension("borg.item", [item_source], extra_compile_args=cflags),
         Extension("borg.item", [item_source], extra_compile_args=cflags),
         Extension("borg.chunkers.buzhash", [buzhash_source], extra_compile_args=cflags, undef_macros=["NDEBUG"]),
         Extension("borg.chunkers.buzhash", [buzhash_source], extra_compile_args=cflags, undef_macros=["NDEBUG"]),
-        Extension("borg.chunkers.chunker", [chunker_source], extra_compile_args=cflags, undef_macros=["NDEBUG"]),
         Extension("borg.chunkers.reader", [reader_source], extra_compile_args=cflags, undef_macros=["NDEBUG"]),
         Extension("borg.chunkers.reader", [reader_source], extra_compile_args=cflags, undef_macros=["NDEBUG"]),
         Extension("borg.checksums", **checksums_ext_kwargs),
         Extension("borg.checksums", **checksums_ext_kwargs),
     ]
     ]

+ 3 - 1
src/borg/chunkers/__init__.py

@@ -1,8 +1,10 @@
 from .buzhash import *  # noqa
 from .buzhash import *  # noqa
-from .chunker import *  # noqa
 from .failing import *  # noqa
 from .failing import *  # noqa
+from .fixed import *  # noqa
 from .reader import *  # noqa
 from .reader import *  # noqa
 
 
+API_VERSION = "1.2_01"
+
 
 
 def get_chunker(algo, *params, **kw):
 def get_chunker(algo, *params, **kw):
     if algo == "buzhash":
     if algo == "buzhash":

+ 0 - 9
src/borg/chunkers/chunker.pyi

@@ -1,9 +0,0 @@
-from typing import List, Iterator, BinaryIO
-
-from .reader import fmap_entry
-
-API_VERSION: str
-
-class ChunkerFixed:
-    def __init__(self, block_size: int, header_size: int = 0, sparse: bool = False) -> None: ...
-    def chunkify(self, fd: BinaryIO = None, fh: int = -1, fmap: List[fmap_entry] = None) -> Iterator: ...

+ 6 - 6
src/borg/chunkers/chunker.pyx → src/borg/chunkers/fixed.py

@@ -1,6 +1,6 @@
-# cython: language_level=3
+from typing import List, Iterator, BinaryIO
 
 
-API_VERSION = '1.2_01'
+API_VERSION = "1.2_01"
 
 
 import time
 import time
 
 
@@ -27,7 +27,8 @@ class ChunkerFixed:
     Note: the last block of a data or hole range may be less than the block size,
     Note: the last block of a data or hole range may be less than the block size,
           this is supported and not considered to be an error.
           this is supported and not considered to be an error.
     """
     """
-    def __init__(self, block_size, header_size=0, sparse=False):
+
+    def __init__(self, block_size: int, header_size: int = 0, sparse: bool = False) -> None:
         self.block_size = block_size
         self.block_size = block_size
         self.header_size = header_size
         self.header_size = header_size
         self.chunking_time = 0.0  # likely will stay close to zero - not much to do here.
         self.chunking_time = 0.0  # likely will stay close to zero - not much to do here.
@@ -35,7 +36,7 @@ class ChunkerFixed:
         self.reader = None
         self.reader = None
         self.sparse = sparse
         self.sparse = sparse
 
 
-    def chunkify(self, fd=None, fh=-1, fmap=None):
+    def chunkify(self, fd: BinaryIO = None, fh: int = -1, fmap: List = None) -> Iterator:
         """
         """
         Cut a file into chunks.
         Cut a file into chunks.
 
 
@@ -45,8 +46,7 @@ class ChunkerFixed:
         :param fmap: a file map, same format as generated by sparsemap
         :param fmap: a file map, same format as generated by sparsemap
         """
         """
         # Initialize the reader with the file descriptors
         # Initialize the reader with the file descriptors
-        self.reader = FileReader(fd=fd, fh=fh, read_size=self.reader_block_size,
-                                sparse=self.sparse, fmap=fmap)
+        self.reader = FileReader(fd=fd, fh=fh, read_size=self.reader_block_size, sparse=self.sparse, fmap=fmap)
 
 
         # Handle header if present
         # Handle header if present
         if self.header_size > 0:
         if self.header_size > 0:

+ 2 - 3
src/borg/helpers/checks.py

@@ -14,13 +14,12 @@ def check_python():
 
 
 
 
 def check_extension_modules():
 def check_extension_modules():
-    from .. import platform, compress, crypto, item, hashindex
-    from ..chunkers import chunker
+    from .. import platform, compress, crypto, item, hashindex, chunkers
 
 
     msg = """The Borg binary extension modules do not seem to be properly installed."""
     msg = """The Borg binary extension modules do not seem to be properly installed."""
     if hashindex.API_VERSION != "1.2_01":
     if hashindex.API_VERSION != "1.2_01":
         raise RTError(msg)
         raise RTError(msg)
-    if chunker.API_VERSION != "1.2_01":
+    if chunkers.API_VERSION != "1.2_01":
         raise RTError(msg)
         raise RTError(msg)
     if compress.API_VERSION != "1.2_02":
     if compress.API_VERSION != "1.2_02":
         raise RTError(msg)
         raise RTError(msg)