changeset 18213:c38a62af000e

vfs: add a read only vfs This read only wrapper is intended to be used bundle repo. See follow up commit for details.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 04 Jan 2013 01:07:25 +0100
parents 493778b5fe9f
children cd4c75200206
files mercurial/scmutil.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/scmutil.py	Sat Dec 22 19:41:11 2012 +0100
+++ b/mercurial/scmutil.py	Fri Jan 04 01:07:25 2013 +0100
@@ -382,6 +382,18 @@
 
 filteropener = filtervfs
 
+class readonlyvfs(abstractvfs, auditvfs):
+    '''Wrapper vfs preventing any writing.'''
+
+    def __init__(self, vfs):
+        auditvfs.__init__(self, vfs)
+
+    def __call__(self, path, mode='r', *args, **kw):
+        if mode not in ('r', 'rb'):
+            raise util.Abort('this vfs is read only')
+        return self.vfs(path, mode, *args, **kw)
+
+
 def canonpath(root, cwd, myname, auditor=None):
     '''return the canonical path of myname, given cwd and root'''
     if util.endswithsep(root):