From 13e6970437e9d706b39f8d3fcbc2155d5dd0b702 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 6 Jul 2018 22:45:24 +0200 Subject: [PATCH] create: do not give chunker a py file object, it is not needed the os level file handle is enough, the chunker will prefer it if valid and won't use the file obj, so we can give None there. this saves these unneeded syscalls: fstat(5, {st_mode=S_IFREG|0664, st_size=227063, ...}) = 0 ioctl(5, TCGETS, 0x7ffd635635f0) = -1 ENOTTY (Inappropriate ioctl for device) lseek(5, 0, SEEK_CUR) = 0 --- src/borg/archive.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index 97c5cffa2..d65f2abfc 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -1151,13 +1151,15 @@ class FilesystemObjectProcessors: else: with backup_io('open'): fh = Archive._open_rb(path) - with os.fdopen(fh, 'rb') as fd: - self.process_file_chunks(item, cache, self.stats, self.show_progress, backup_io_iter(self.chunker.chunkify(fd, fh))) - md = self.metadata_collector.stat_attrs(st, path, fd=fh) - if not is_special_file: - # we must not memorize special files, because the contents of e.g. a - # block or char device will change without its mtime/size/inode changing. - cache.memorize_file(path_hash, st, [c.id for c in item.chunks]) + try: + self.process_file_chunks(item, cache, self.stats, self.show_progress, backup_io_iter(self.chunker.chunkify(None, fh))) + md = self.metadata_collector.stat_attrs(st, path, fd=fh) + finally: + os.close(fh) + if not is_special_file: + # we must not memorize special files, because the contents of e.g. a + # block or char device will change without its mtime/size/inode changing. + cache.memorize_file(path_hash, st, [c.id for c in item.chunks]) self.stats.nfiles += 1 if md is None: fh = Archive._open_rb(path)