# HG changeset patch # User Tero Marttila # Date 1392667606 -7200 # Node ID 5698225aab66600d33c0b9bde030956bd78ff950 # Parent 0e79da714c19ec7f25bb4a37c2a2e9724ba2862b pvl.backup.mount: fix close() in case of mount root not giving us read permissions diff -r 0e79da714c19 -r 5698225aab66 pvl/backup/mount.py --- a/pvl/backup/mount.py Wed May 01 00:38:58 2013 +0300 +++ b/pvl/backup/mount.py Mon Feb 17 22:06:46 2014 +0200 @@ -61,7 +61,7 @@ if not os.path.isdir(self.mnt) : raise MountError("Mountpoint is not a directory: {mnt}".format(mnt=self.mnt)) - if os.path.ismount(self.mnt) : + if self.is_mounted() : raise MountError("Mountpoint is already mounted: {mnt}".format(mnt=self.mnt)) if not os.path.exists(self.dev) : @@ -70,13 +70,25 @@ # mount invoke(self.MOUNT, optargs(self.dev, self.mnt, options=self.options()), sudo=self.sudo) + def is_mounted (self) : + """ + Test if the given mountpoint is mounted. + """ + + # workaround http://bugs.python.org/issue2466 + if os.path.exists(self.mnt) and not os.path.exists(os.path.join(self.mnt, '.')) : + # this is a sign of a mountpoint that we do not have access to + return True + + return os.path.ismount(self.mnt) + def close (self) : """ Un-mount """ # check - if not os.path.ismount(self.mnt): + if not self.is_mounted() : raise MountError("Mountpoint is not mounted: {mnt}".format(mnt=self.mnt)) # umount @@ -127,7 +139,12 @@ finally: # cleanup log.debug("cleanup: %s", mount) - mount.close() + + try : + mount.close() + + except Exception as ex : + log.warning("cleanup: %s: %s", mount, ex) finally: if tmpdir :