tests/test-symlink-os-yes-fs-no.py
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48875 6000f5b25c9b
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28916
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     1
import os
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     2
import sys
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     3
import time
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     4
from mercurial import (
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     5
    commands,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     6
    hg,
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
     7
    pycompat,
28916
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     8
    ui as uimod,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     9
    util,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    10
)
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    11
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    12
TESTDIR = os.environ["TESTDIR"]
14116
cd3032437064 tests: move test bundles in a bundles/ subdirectory
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11769
diff changeset
    13
BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg')
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    14
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    15
# only makes sense to test on os which supports symlinks
14971
0b21ae0a2366 tests: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14553
diff changeset
    16
if not getattr(os, "symlink", False):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    17
    sys.exit(80)  # SKIPPED_STATUS defined in run-tests.py
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    18
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    19
u = uimod.ui.load()
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    20
# hide outer repo
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    21
hg.peer(u, {}, b'.', create=True)
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    22
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    23
# unbundle with symlink support
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    24
hg.peer(u, {}, b'test0', create=True)
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    25
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    26
repo = hg.repository(u, b'test0')
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    27
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True)
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    28
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    29
# wait a bit, or the status call wont update the dirstate
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    30
time.sleep(1)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    31
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    32
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    33
# now disable symlink support -- this is what os.symlink would do on a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    34
# non-symlink file system
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    35
def symlink_failure(src, dst):
18178
6ae45c0b4625 test-symlink-os-yes-fs-no.py: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents: 17015
diff changeset
    36
    raise OSError(1, "Operation not permitted")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    37
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    38
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    39
os.symlink = symlink_failure
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    40
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    41
30448
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    42
def islink_failure(path):
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    43
    return False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    44
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37935
diff changeset
    45
30448
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    46
os.path.islink = islink_failure
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    47
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    48
# dereference links as if a Samba server has exported this to a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    49
# Windows client
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    50
for f in b'test0/a.lnk', b'test0/d/b.lnk':
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    51
    os.unlink(f)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    52
    fp = open(f, 'wb')
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14116
diff changeset
    53
    fp.write(util.readfile(f[:-4]))
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    54
    fp.close()
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    55
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    56
# reload repository
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    57
u = uimod.ui.load()
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    58
repo = hg.repository(u, b'test0')
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    59
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    60
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    61
# try unbundling a repo which contains symlinks
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    62
u = uimod.ui.load()
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    63
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    64
repo = hg.repository(u, b'test1', create=True)
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    65
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True)