X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbup%2Fhashsplit.py;h=3cbcfc981b4e1280604712b2b0ffe2fbeff9411e;hb=c40b3dd5fd74e72024fbaad3daf5a958aefa1c54;hp=9631605a4b9b9281271bb2eb75bf27f661f81674;hpb=6178db0ca9a784fa9961d2de5b29090c3c4c3e03;p=bup.git diff --git a/lib/bup/hashsplit.py b/lib/bup/hashsplit.py index 9631605..3cbcfc9 100644 --- a/lib/bup/hashsplit.py +++ b/lib/bup/hashsplit.py @@ -1,4 +1,6 @@ -import math, os + +from __future__ import absolute_import +import io, math, os from bup import _helpers, helpers from bup.helpers import sc_page_size @@ -11,10 +13,9 @@ MAX_PER_TREE = 256 progress_callback = None fanout = 16 -GIT_MODE_FILE = 0100644 -GIT_MODE_TREE = 040000 -GIT_MODE_SYMLINK = 0120000 -assert(GIT_MODE_TREE != 40000) # 0xxx should be treated as octal +GIT_MODE_FILE = 0o100644 +GIT_MODE_TREE = 0o40000 +GIT_MODE_SYMLINK = 0o120000 # The purpose of this type of buffer is to avoid copying on peek(), get(), # and eat(). We do copy the buffer contents on put(), but that should @@ -53,7 +54,7 @@ def _fadvise_pages_done(fd, first_page, count): count * sc_page_size) -def _nonresident_page_regions(status_bytes, max_region_len=None): +def _nonresident_page_regions(status_bytes, incore_mask, max_region_len=None): """Return (start_page, count) pairs in ascending start_page order for each contiguous region of nonresident pages indicated by the mincore() status_bytes. Limit the number of pages in each region @@ -61,7 +62,7 @@ def _nonresident_page_regions(status_bytes, max_region_len=None): assert(max_region_len is None or max_region_len > 0) start = None for i, x in enumerate(status_bytes): - in_core = x & helpers.MINCORE_INCORE + in_core = x & incore_mask if start is None: if not in_core: start = i @@ -95,10 +96,17 @@ def readfile_iter(files, progress=None): b = '' fd = rpr = rstart = rlen = None if _fmincore and hasattr(f, 'fileno'): - fd = f.fileno() - max_chunk = max(1, (8 * 1024 * 1024) / sc_page_size) - rpr = _nonresident_page_regions(_fmincore(fd), max_chunk) - rstart, rlen = next(rpr, (None, None)) + try: + fd = f.fileno() + except io.UnsupportedOperation: + pass + if fd: + mcore = _fmincore(fd) + if mcore: + max_chunk = max(1, (8 * 1024 * 1024) / sc_page_size) + rpr = _nonresident_page_regions(mcore, helpers.MINCORE_INCORE, + max_chunk) + rstart, rlen = next(rpr, (None, None)) while 1: if progress: progress(filenum, len(b))