"""
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
|
Loading...