]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/hashsplit.py
Revert "Avoid fadvise (since it doesn't work as expected)"
[bup.git] / lib / bup / hashsplit.py
index 987cadb09142581c4a6e4941091c855e90d9a156..571ddf6434ac1723c1948ffc5c4ba6f59843a72c 100644 (file)
@@ -50,6 +50,9 @@ def readfile_iter(files, progress=None):
                 progress(filenum, len(b))
             b = f.read(BLOB_READ_SIZE)
             ofs += len(b)
+            # Warning: ofs == 0 means 'done with the whole file'
+            # This will only happen here when the file is empty
+            fadvise_done(f, ofs)
             if not b:
                 break
             yield b
@@ -188,3 +191,9 @@ def open_noatime(name):
         except:
             pass
         raise
+
+
+def fadvise_done(f, ofs):
+    assert(ofs >= 0)
+    if ofs > 0 and hasattr(f, 'fileno'):
+        _helpers.fadvise_done(f.fileno(), ofs)