aboutsummaryrefslogtreecommitdiff
path: root/tests/hard-link-sym.py
blob: 59fb3b6df5c4794ebb2f2a915a03c2ab357a446c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from errno import *

###############################################################################
#
# Try to hardlink symlinks
#
###############################################################################

# Hard link a symlink
def subtest_1(ctx):
    """Hard link symlink"""
    f = ctx.direct_sym() + ctx.termslash()
    f2 = ctx.no_file() + ctx.termslash()

    ctx.link(f, f2)
    ctx.open_file(f, ro=1, read=":xxx:yyy:zzz")
    ctx.open_file(f2, ro=1, read=":xxx:yyy:zzz")

# Hard link a dangling symlink
def subtest_2(ctx):
    """Hard link dangling symlink"""
    f = ctx.pointless() + ctx.termslash()
    f2 = ctx.no_file() + ctx.termslash()

    ctx.link(f, f2)
    ctx.open_file(f, ro=1, err=ELOOP)
    ctx.open_file(f2, ro=1, err=ELOOP)

# Hard link a non-existent file over a symlink
def subtest_3(ctx):
    """Hard link non-existent file over a symlink"""
    f = ctx.no_file() + ctx.termslash()
    f2 = ctx.direct_sym() + ctx.termslash()

    ctx.link(f, f2, err=ENOENT)
    ctx.open_file(f, ro=1, err=ENOENT)
    ctx.open_file(f2, ro=1, read=":xxx:yyy:zzz")

# Hard link a symlink over a file
def subtest_4(ctx):
    """Hard link symlink over file"""
    f = ctx.direct_sym() + ctx.termslash()
    f2 = ctx.non_empty_dir() + "/a" + ctx.termslash()

    ctx.link(f, f2, err=EEXIST)
    ctx.open_file(f, ro=1, read=":xxx:yyy:zzz")
    ctx.open_file(f2, ro=1, read="")

# Hard link a symlink over a new file
def subtest_5(ctx):
    """Hard link symlink over new file"""
    f = ctx.direct_sym() + ctx.termslash()
    f2 = ctx.reg_file() + "-new" + ctx.termslash()

    ctx.open_file(f2, wo=1, crt=1, write="aaaa")
    ctx.link(f, f2, err=EEXIST)
    ctx.open_file(f, ro=1, read=":xxx:yyy:zzz")
    ctx.open_file(f2, ro=1, read="aaaa")

# Hard link a new file over a symlink
def subtest_6(ctx):
    """Hard link new file over symlink"""
    f = ctx.reg_file() + "-new" + ctx.termslash()
    f2 = ctx.direct_sym() + ctx.termslash()

    ctx.open_file(f, wo=1, crt=1, write="aaaa")
    ctx.link(f, f2, err=EEXIST)
    ctx.open_file(f, ro=1, read="aaaa")
    ctx.open_file(f2, ro=1, read=":xxx:yyy:zzz")

# Hard link a symlink over itself
def subtest_7(ctx):
    """Hard link symlink over itself"""
    f = ctx.direct_sym() + ctx.termslash()

    ctx.link(f, f, err=EEXIST)
    ctx.open_file(f, ro=1, read=":xxx:yyy:zzz")

# Hard link a symlink over another symlink
def subtest_8(ctx):
    """Hard link symlink over another symlink"""
    f = ctx.direct_sym() + ctx.termslash()
    f2 = ctx.pointless() + ctx.termslash()

    ctx.link(f, f2, err=EEXIST)
    ctx.open_file(f, ro=1, read=":xxx:yyy:zzz")
    ctx.open_file(f2, ro=1, err=ENOENT)

# Hard link an unlinked symlink
def subtest_9(ctx):
    """Hard link unlinked symlink"""
    f = ctx.direct_sym() + ctx.termslash()
    f2 = ctx.no_file() + ctx.termslash()

    ctx.unlink(f)
    ctx.link(f, f2, err=ENOENT)
    ctx.open_file(f, ro=1, err=ENOENT)
    ctx.open_file(f2, ro=1, err=ENOENT)

# Hard link a renamed symlink
def subtest_10(ctx):
    """Hard link renamed symlink"""
    f = ctx.direct_sym() + ctx.termslash()
    f2 = ctx.no_file() + ctx.termslash()
    f3 = ctx.no_file() + "-a" + ctx.termslash()

    ctx.rename(f, f2)
    ctx.link(f, f3, err=ENOENT)
    ctx.link(f2, f)
    ctx.open_file(f, ro=1, read=":xxx:yyy:zzz")
    ctx.open_file(f2, ro=1, read=":xxx:yyy:zzz")
    ctx.open_file(f3, ro=1, err=ENOENT)