From 2d050eaaf9d8619d88bfd282c30566ad17c304eb Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Mon, 15 Apr 2019 23:51:00 -0700 Subject: [PATCH] Check for presence of lockfile value before proceeding with context manager --- rbackup/plugins/packagemanager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rbackup/plugins/packagemanager.py b/rbackup/plugins/packagemanager.py index 6213888..eba8a2d 100644 --- a/rbackup/plugins/packagemanager.py +++ b/rbackup/plugins/packagemanager.py @@ -71,14 +71,16 @@ class PackageManager: :rtype: ``PackageManager`` object :raises FileExistsError: if lockfile exists when this method is called """ - self._lockfile.touch(mode=0o000) + if self._lockfile: + self._lockfile.touch(mode=0o000, exist_ok=False) yield self def __exit__(self): """Remove the package manager's lockfile. After this lockfile is closed, the package manager this class abstracts can perform transactions once again. """ - self._lockfile.unlink() + if self._lockfile: + self._lockfile.unlink() def gen_pkglist(self): """Generate a text file listing installed packages