Commit e2db66b5 by btimby

Some optimized paths to avoid mounting an archive if we don't need to.

Also, a check to ensure that makedirs() behaves as expected when trying to create a directory on top of an archive.
parent 57ba0a2a
...@@ -234,6 +234,11 @@ class ArchiveMountFS(mountfs.MountFS): ...@@ -234,6 +234,11 @@ class ArchiveMountFS(mountfs.MountFS):
# that modify files (and therefore archives). See remove() below to see # that modify files (and therefore archives). See remove() below to see
# why. # why.
def getsyspath(self, path):
# Optimized getsyspath() that avoids calling _delegate() and thus
# mounting an archive.
return self.rootfs.getsyspath(path)
def remove(self, path): def remove(self, path):
# In case one of our mounted file systems backing archive is being # In case one of our mounted file systems backing archive is being
# deleted, unmout it before continuing. Once unmounted, the archive # deleted, unmout it before continuing. Once unmounted, the archive
...@@ -247,6 +252,14 @@ class ArchiveMountFS(mountfs.MountFS): ...@@ -247,6 +252,14 @@ class ArchiveMountFS(mountfs.MountFS):
# Otherwise, just delegate to the responsible fs. # Otherwise, just delegate to the responsible fs.
return super(ArchiveMountFS, self).remove(path) return super(ArchiveMountFS, self).remove(path)
def makedir(self, path, *args, **kwargs):
# If the caller is trying to create a directory where an archive lives
# we should raise an error. In the case when allow_recreate=True, this
# call would succeed without the check below.
if self.rootfs.isfile(path):
raise ResourceInvalidError(path,msg="Cannot create directory, there's already a file of that name: %(path)s")
return super(ArchiveFS, self).makedir(path, *args, **kwargs)
def main(): def main():
ArchiveFS() ArchiveFS()
......
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