| 1 |
import os |
| 2 |
import sys |
| 3 |
import time |
| 4 |
from mercurial import ( |
| 5 |
commands, |
| 6 |
initialization, |
| 7 |
policy, |
| 8 |
pycompat, |
| 9 |
ui as uimod, |
| 10 |
util, |
| 11 |
) |
| 12 |
from mercurial.repo import factory |
| 13 |
|
| 14 |
initialization.init() |
| 15 |
|
| 16 |
TESTDIR = os.environ["TESTDIR"] |
| 17 |
BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg') |
| 18 |
SKIPPED_RETURN_CODE = 80 # SKIPPED_STATUS defined in run-tests.py |
| 19 |
|
| 20 |
if policy.importrust('revlog') is not None: |
| 21 |
# Rust cannot be monkey-patched and has no support for systems without |
| 22 |
# symlinks yet. |
| 23 |
sys.exit(SKIPPED_RETURN_CODE) |
| 24 |
|
| 25 |
# only makes sense to test on os which supports symlinks |
| 26 |
if not getattr(os, "symlink", False): |
| 27 |
sys.exit(SKIPPED_RETURN_CODE) |
| 28 |
|
| 29 |
u = uimod.ui.load() |
| 30 |
# hide outer repo |
| 31 |
factory.peer(u, {}, b'.', create=True) |
| 32 |
|
| 33 |
# unbundle with symlink support |
| 34 |
factory.peer(u, {}, b'test0', create=True) |
| 35 |
|
| 36 |
repo = factory.repository(u, b'test0') |
| 37 |
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True) |
| 38 |
|
| 39 |
# wait a bit, or the status call wont update the dirstate |
| 40 |
time.sleep(1) |
| 41 |
commands.status(u, repo) |
| 42 |
|
| 43 |
|
| 44 |
# now disable symlink support -- this is what os.symlink would do on a |
| 45 |
# non-symlink file system |
| 46 |
def symlink_failure(src, dst): |
| 47 |
raise OSError(1, "Operation not permitted") |
| 48 |
|
| 49 |
|
| 50 |
os.symlink = symlink_failure |
| 51 |
|
| 52 |
|
| 53 |
def islink_failure(path): |
| 54 |
return False |
| 55 |
|
| 56 |
|
| 57 |
os.path.islink = islink_failure |
| 58 |
|
| 59 |
# dereference links as if a Samba server has exported this to a |
| 60 |
# Windows client |
| 61 |
for f in b'test0/a.lnk', b'test0/d/b.lnk': |
| 62 |
os.unlink(f) |
| 63 |
fp = open(f, 'wb') |
| 64 |
fp.write(util.readfile(f[:-4])) |
| 65 |
fp.close() |
| 66 |
|
| 67 |
# reload repository |
| 68 |
u = uimod.ui.load() |
| 69 |
repo = factory.repository(u, b'test0') |
| 70 |
commands.status(u, repo) |
| 71 |
|
| 72 |
# try unbundling a repo which contains symlinks |
| 73 |
u = uimod.ui.load() |
| 74 |
|
| 75 |
repo = factory.repository(u, b'test1', create=True) |
| 76 |
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True) |