Commit f5fca02f by btimby

Take advantage of MountFS.close(), allow turning auto_mount off.

parent 82cfcf09
...@@ -195,15 +195,15 @@ class ArchiveFS(FS): ...@@ -195,15 +195,15 @@ class ArchiveFS(FS):
class ArchiveMountFS(mountfs.MountFS): class ArchiveMountFS(mountfs.MountFS):
'''A subclass of MountFS that automatically identifies archives. Once identified '''A subclass of MountFS that automatically identifies archives. Once identified
archives are mounted in place of the archive file.''' archives are mounted in place of the archive file.'''
def __init__(self, rootfs, **kwargs): def __init__(self, rootfs, auto_mount=True):
super(ArchiveMountFS, self).__init__(**kwargs) self.auto_mount = auto_mount
super(ArchiveMountFS, self).__init__(auto_close=True)
self.rootfs = rootfs self.rootfs = rootfs
self.mountdir('/', rootfs) self.mountdir('/', rootfs)
def __del__(self): def __del__(self):
# Umount everything that we mounted. # Close automatically.
for mountpoint in self.mount_tree.keys(): self.close()
self.unmount(mountpoint)
def ismount(self, path): def ismount(self, path):
try: try:
...@@ -213,20 +213,21 @@ class ArchiveMountFS(mountfs.MountFS): ...@@ -213,20 +213,21 @@ class ArchiveMountFS(mountfs.MountFS):
return type(object) is mountfs.MountFS.DirMount return type(object) is mountfs.MountFS.DirMount
def _delegate(self, path): def _delegate(self, path):
for ppath in recursepath(path)[1:]: if self.auto_mount:
# Don't mount again... for ppath in recursepath(path)[1:]:
if self.ismount(ppath): # Don't mount again...
break if self.ismount(ppath):
if libarchive.is_archive_name(ppath): break
# It looks like an archive, try mounting it. if libarchive.is_archive_name(ppath):
full_path = self.rootfs.getsyspath(ppath) # It looks like an archive, try mounting it.
try: full_path = self.rootfs.getsyspath(ppath)
self.mountdir(ppath, ArchiveFS(full_path, 'r')) try:
except: self.mountdir(ppath, ArchiveFS(full_path, 'r'))
pass # Must NOT have been an archive after all except:
# Stop recursing path, we support just one archive per path! pass # Must NOT have been an archive after all
# No nested archives yet! # Stop recursing path, we support just one archive per path!
break # No nested archives yet!
break
return super(ArchiveMountFS, self)._delegate(path) return super(ArchiveMountFS, self)._delegate(path)
# TODO: probably need to override move(), movedir() and any other methods # TODO: probably need to override move(), movedir() and any other methods
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment