test-symlink-os-yes-fs-no.py
57 lines
| 1.3 KiB
| text/x-python
|
PythonLexer
/ tests / test-symlink-os-yes-fs-no.py
Pulkit Goyal
|
r28916 | from __future__ import absolute_import | ||
import os | ||||
import sys | ||||
import time | ||||
from mercurial import ( | ||||
commands, | ||||
hg, | ||||
ui as uimod, | ||||
util, | ||||
) | ||||
Dov Feldstern
|
r6879 | |||
TESTDIR = os.environ["TESTDIR"] | ||||
Nicolas Dumazet
|
r14116 | BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg') | ||
Dov Feldstern
|
r6879 | |||
# only makes sense to test on os which supports symlinks | ||||
Augie Fackler
|
r14971 | if not getattr(os, "symlink", False): | ||
Dov Feldstern
|
r6879 | sys.exit(80) # SKIPPED_STATUS defined in run-tests.py | ||
Yuya Nishihara
|
r30559 | u = uimod.ui.load() | ||
Mads Kiilerich
|
r17015 | # hide outer repo | ||
hg.peer(u, {}, '.', create=True) | ||||
Martin Geisler
|
r11769 | # clone with symlink support | ||
Peter Arrenbrecht
|
r14553 | hg.clone(u, {}, BUNDLEPATH, 'test0') | ||
Martin Geisler
|
r11769 | |||
repo = hg.repository(u, 'test0') | ||||
# 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 | ||||
Dov Feldstern
|
r6879 | def symlink_failure(src, dst): | ||
Augie Fackler
|
r18178 | raise OSError(1, "Operation not permitted") | ||
Dov Feldstern
|
r6879 | os.symlink = symlink_failure | ||
Mads Kiilerich
|
r30448 | def islink_failure(path): | ||
return False | ||||
os.path.islink = islink_failure | ||||
Dov Feldstern
|
r6879 | |||
Martin Geisler
|
r11769 | # dereference links as if a Samba server has exported this to a | ||
# Windows client | ||||
for f in 'test0/a.lnk', 'test0/d/b.lnk': | ||||
os.unlink(f) | ||||
fp = open(f, 'wb') | ||||
Dan Villiom Podlaski Christiansen
|
r14168 | fp.write(util.readfile(f[:-4])) | ||
Martin Geisler
|
r11769 | fp.close() | ||
# reload repository | ||||
Yuya Nishihara
|
r30559 | u = uimod.ui.load() | ||
Martin Geisler
|
r11769 | repo = hg.repository(u, 'test0') | ||
commands.status(u, repo) | ||||
# try cloning a repo which contains symlinks | ||||
Yuya Nishihara
|
r30559 | u = uimod.ui.load() | ||
Peter Arrenbrecht
|
r14553 | hg.clone(u, {}, BUNDLEPATH, 'test1') | ||