]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/hashsplit.py
Handle mincore cross-platform differences
[bup.git] / lib / bup / hashsplit.py
index 5df627f7f04bb3a651f3a5039601a336360a6282..9631605a4b9b9281271bb2eb75bf27f661f81674 100644 (file)
@@ -1,12 +1,9 @@
 import math, os
 
-from bup import _helpers
+from bup import _helpers, helpers
 from bup.helpers import sc_page_size
 
-try:
-    _fmincore = _helpers.fmincore
-except AttributeError, e:
-    _fmincore = None
+_fmincore = getattr(helpers, 'fmincore', None)
 
 BLOB_MAX = 8192*4   # 8192 is the "typical" blob size for bupsplit
 BLOB_READ_SIZE = 1024*1024
@@ -64,7 +61,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 = ord(x) & 1
+        in_core = x & helpers.MINCORE_INCORE
         if start is None:
             if not in_core:
                 start = i
@@ -100,7 +97,7 @@ def readfile_iter(files, progress=None):
         if _fmincore and hasattr(f, 'fileno'):
             fd = f.fileno()
             max_chunk = max(1, (8 * 1024 * 1024) / sc_page_size)
-            rpr = _nonresident_page_regions(_helpers.fmincore(fd), max_chunk)
+            rpr = _nonresident_page_regions(_fmincore(fd), max_chunk)
             rstart, rlen = next(rpr, (None, None))
         while 1:
             if progress: