Kiln » Kiln Storage Service Read More
Clone URL:  
nosymlink.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
""" Because Mercurial and OpenGrok happily allow and follow symlinks, we have to make sure that we are not creating them, as that would be a major security problem. Thus, we patch mercurial's localrepo object by wrapping the wwrite() method to be a no-op if 'l' is in the `flags` parameter. See http://bitbucket.org/mirror/mercurial/src/c5d40818b270/mercurial/localrepo.py#cl-554 """ import os def reposetup(ui, repo): if not repo.local(): return class nosymlinkrepo(repo.__class__): def wwrite(self, filename, data, flags): if 'l' in flags: # From mercurial.localrepo.wwrite try: os.unlink(self.wjoin(filename)) except OSError: pass # /From mercurial.localrepo.wwrite # We need the file to exist, though. Otherwise the dirstate is broken. self.wopener(filename, 'w').write('') return return super(nosymlinkrepo, self).wwrite(filename, data, flags) repo.__class__ = nosymlinkrepo