@@ -16,12 +16,14 @@ main = do
16
16
fs <- testRegular
17
17
ds <- testDir
18
18
testSymlink fs ds
19
+ testLink
19
20
cleanup
20
21
21
- regular = " regular"
22
- dir = " dir"
23
- link_regular = " link-regular"
24
- link_dir = " link-dir"
22
+ regular = " regular"
23
+ dir = " dir"
24
+ slink_regular = " link-regular-symlink"
25
+ hlink_regular = " link-regular-hardlink"
26
+ link_dir = " link-dir"
25
27
26
28
testRegular = do
27
29
_ <- createFile regular ownerReadMode
@@ -42,9 +44,9 @@ testDir = do
42
44
return ds
43
45
44
46
testSymlink fs ds = do
45
- createSymbolicLink regular link_regular
47
+ createSymbolicLink regular slink_regular
46
48
createSymbolicLink dir link_dir
47
- (fs', ls) <- getStatus link_regular
49
+ (fs', ls) <- getStatus slink_regular
48
50
(ds', lds) <- getStatus link_dir
49
51
50
52
let expected = (False ,False ,False ,False ,False ,True ,False )
@@ -63,10 +65,35 @@ testSymlink fs ds = do
63
65
when (statusElements ds /= statusElements ds') $
64
66
fail " status for a directory does not match when it's accessed via a symlink"
65
67
68
+
69
+ testLink = do
70
+ createLink regular hlink_regular
71
+ (fs, _) <- getStatus regular -- we need to retrieve it again as creating the link causes it to change!
72
+ (fs', ls) <- getStatus hlink_regular
73
+ let expected = (
74
+ False , -- isBlockDevice
75
+ False , -- isCharacterDevice
76
+ False , -- isNamedPipe
77
+ True , -- isRegularFile
78
+ False , -- isDirectory
79
+ False , -- isSymbolicLink
80
+ False ) -- isSocket
81
+ actualF = snd (statusElements ls)
82
+
83
+ when (actualF /= expected) $
84
+ fail " unexpected file status bits for hard link to regular file"
85
+
86
+ when (linkCount fs' /= 2 ) $
87
+ fail " newly created hard link was expected to contain have a link count of 2"
88
+
89
+ when (statusElements fs /= statusElements fs') $
90
+ fail " status for a file does not match when it's accessed via a link"
91
+
92
+
66
93
cleanup = do
67
94
ignoreIOExceptions $ removeDirectory dir
68
95
mapM_ (ignoreIOExceptions . removeLink)
69
- [regular, link_regular , link_dir]
96
+ [regular, hlink_regular, slink_regular , link_dir]
70
97
71
98
ignoreIOExceptions io = io `E.catch`
72
99
((\ _ -> return () ) :: IOException -> IO () )
0 commit comments