From ed1e5e9c13228ee71cea1e0f4417527902068e30 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 31 May 2015 21:23:36 +0200 Subject: [PATCH 1/2] "create" micro optimization: do not check for sockets early they are rare, so it's pointless to check for them first. seen the stat..S_ISSOCK in profiling results with high call count. was no big issue, that call is cheap, but also no big issue to just fix the order. --- borg/archiver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 4b13e47fd..438418abb 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -168,9 +168,6 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") # Entering a new filesystem? if restrict_dev and st.st_dev != restrict_dev: return - # Ignore unix sockets - if stat.S_ISSOCK(st.st_mode): - return status = None if stat.S_ISREG(st.st_mode): try: @@ -196,6 +193,9 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") status = archive.process_fifo(path, st) elif stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode): status = archive.process_dev(path, st) + elif stat.S_ISSOCK(st.st_mode): + # Ignore unix sockets + return else: self.print_error('Unknown file type: %s', path) return From 646cdca312f3ebb87a186af3d1f088b54d4a6a7d Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 31 May 2015 21:53:37 +0200 Subject: [PATCH 2/2] "extract" micro optimization: first check for regular files, then for directories, check for fifos late regular files are most common, more than directories. fifos are rare. was no big issue, the calls are cheap, but also no big issue to just fix the order. --- borg/archive.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/borg/archive.py b/borg/archive.py index 3eccbbeef..e6d557479 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -273,12 +273,7 @@ class Archive: except OSError: pass mode = item[b'mode'] - if stat.S_ISDIR(mode): - if not os.path.exists(path): - os.makedirs(path) - if restore_attrs: - self.restore_attrs(path, item) - elif stat.S_ISREG(mode): + if stat.S_ISREG(mode): if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) # Hard link? @@ -300,11 +295,11 @@ class Archive: fd.truncate(pos) fd.flush() self.restore_attrs(path, item, fd=fd.fileno()) - elif stat.S_ISFIFO(mode): - if not os.path.exists(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) - os.mkfifo(path) - self.restore_attrs(path, item) + elif stat.S_ISDIR(mode): + if not os.path.exists(path): + os.makedirs(path) + if restore_attrs: + self.restore_attrs(path, item) elif stat.S_ISLNK(mode): if not os.path.exists(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) @@ -313,6 +308,11 @@ class Archive: os.unlink(path) os.symlink(source, path) self.restore_attrs(path, item, symlink=True) + elif stat.S_ISFIFO(mode): + if not os.path.exists(os.path.dirname(path)): + os.makedirs(os.path.dirname(path)) + os.mkfifo(path) + self.restore_attrs(path, item) elif stat.S_ISCHR(mode) or stat.S_ISBLK(mode): os.mknod(path, item[b'mode'], item[b'rdev']) self.restore_attrs(path, item)