test-symlink-os-yes-fs-no.py
61 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
/ tests / test-symlink-os-yes-fs-no.py
|
r28916 | from __future__ import absolute_import | ||
import os | ||||
import sys | ||||
import time | ||||
from mercurial import ( | ||||
commands, | ||||
hg, | ||||
|
r37954 | pycompat, | ||
|
r28916 | ui as uimod, | ||
util, | ||||
) | ||||
|
r6879 | |||
TESTDIR = os.environ["TESTDIR"] | ||||
|
r14116 | BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg') | ||
|
r6879 | |||
# only makes sense to test on os which supports symlinks | ||||
|
r14971 | if not getattr(os, "symlink", False): | ||
|
r6879 | sys.exit(80) # SKIPPED_STATUS defined in run-tests.py | ||
|
r30559 | u = uimod.ui.load() | ||
|
r17015 | # hide outer repo | ||
|
r37954 | hg.peer(u, {}, b'.', create=True) | ||
|
r17015 | |||
|
r37449 | # unbundle with symlink support | ||
|
r37954 | hg.peer(u, {}, b'test0', create=True) | ||
|
r11769 | |||
|
r37954 | repo = hg.repository(u, b'test0') | ||
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True) | ||||
|
r11769 | |||
# wait a bit, or the status call wont update the dirstate | ||||
time.sleep(1) | ||||
commands.status(u, repo) | ||||
# now disable symlink support -- this is what os.symlink would do on a | ||||
# non-symlink file system | ||||
|
r6879 | def symlink_failure(src, dst): | ||
|
r18178 | raise OSError(1, "Operation not permitted") | ||
|
r6879 | os.symlink = symlink_failure | ||
|
r30448 | def islink_failure(path): | ||
return False | ||||
os.path.islink = islink_failure | ||||
|
r6879 | |||
|
r11769 | # dereference links as if a Samba server has exported this to a | ||
# Windows client | ||||
|
r37954 | for f in b'test0/a.lnk', b'test0/d/b.lnk': | ||
|
r11769 | os.unlink(f) | ||
fp = open(f, 'wb') | ||||
|
r14168 | fp.write(util.readfile(f[:-4])) | ||
|
r11769 | fp.close() | ||
# reload repository | ||||
|
r30559 | u = uimod.ui.load() | ||
|
r37954 | repo = hg.repository(u, b'test0') | ||
|
r11769 | commands.status(u, repo) | ||
|
r37449 | # try unbundling a repo which contains symlinks | ||
|
r30559 | u = uimod.ui.load() | ||
|
r37449 | |||
|
r37954 | repo = hg.repository(u, b'test1', create=True) | ||
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True) | ||||