|
21 | 21 | module System.Posix.Directory.Common (
|
22 | 22 | DirStream(..), DirEnt(..), CDir, CDirent, DirStreamOffset(..),
|
23 | 23 | DirType( DirType
|
24 |
| - , DtUnknown |
25 |
| - , DtFifo |
26 |
| - , DtChr |
27 |
| - , DtDir |
28 |
| - , DtBlk |
29 |
| - , DtReg |
30 |
| - , DtLnk |
31 |
| - , DtSock |
32 |
| - , DtWht |
| 24 | + , UnknownType |
| 25 | + , NamedPipeType |
| 26 | + , CharacterDeviceType |
| 27 | + , DirectoryType |
| 28 | + , BlockDeviceType |
| 29 | + , RegularFileType |
| 30 | + , SymbolicLinkType |
| 31 | + , SocketType |
| 32 | + , WhiteoutType |
33 | 33 | ),
|
| 34 | + isUnknownType, isBlockDeviceType, isCharacterDeviceType, isNamedPipeType, |
| 35 | + isRegularFileType, isDirectoryType, isSymbolicLinkType, isSocketType, |
| 36 | + isWhiteoutType, |
34 | 37 | unsafeOpenDirStreamFd,
|
35 | 38 | readDirStreamWith,
|
36 | 39 | readDirStreamWithPtr,
|
@@ -78,34 +81,88 @@ instance Storable DirEnt where
|
78 | 81 | data {-# CTYPE "DIR" #-} CDir
|
79 | 82 | data {-# CTYPE "struct dirent" #-} CDirent
|
80 | 83 |
|
| 84 | +-- | The value of the @d_type@ field of a @dirent@ struct. |
| 85 | +-- Note that the possible values of that type depend on the filesystem that is |
| 86 | +-- queried. From @readdir(3)@: |
| 87 | +-- |
| 88 | +-- > Currently, only some filesystems (among them: Btrfs, ext2, ext3, and ext4) |
| 89 | +-- > have full support for returning the file type in d_type. All applications |
| 90 | +-- > must properly handle a return of DT_UNKNOWN. |
| 91 | +-- |
| 92 | +-- For example, JFS is a filesystem that does not support @d_type@; |
| 93 | +-- See https://github.com/haskell/ghcup-hs/issues/766 |
| 94 | +-- |
| 95 | +-- Furthermore, @dirent@ or the constants represented by the associated pattern |
| 96 | +-- synonyms of this type may not be provided by the underlying platform. In that |
| 97 | +-- case none of those patterns will match and the application must handle that |
| 98 | +-- case accordingly. |
81 | 99 | newtype DirType = DirType CChar
|
82 |
| - |
83 |
| -pattern DtUnknown :: DirType |
84 |
| -pattern DtUnknown = DirType CONST_DT_UNKNOWN |
85 |
| - |
86 |
| -pattern DtFifo :: DirType |
87 |
| -pattern DtFifo = DirType (CONST_DT_FIFO) |
88 |
| - |
89 |
| -pattern DtChr :: DirType |
90 |
| -pattern DtChr = DirType (CONST_DT_CHR) |
91 |
| - |
92 |
| -pattern DtDir :: DirType |
93 |
| -pattern DtDir = DirType (CONST_DT_DIR) |
94 |
| - |
95 |
| -pattern DtBlk :: DirType |
96 |
| -pattern DtBlk = DirType (CONST_DT_BLK) |
97 |
| - |
98 |
| -pattern DtReg :: DirType |
99 |
| -pattern DtReg = DirType (CONST_DT_REG) |
100 |
| - |
101 |
| -pattern DtLnk :: DirType |
102 |
| -pattern DtLnk = DirType (CONST_DT_LNK) |
103 |
| - |
104 |
| -pattern DtSock :: DirType |
105 |
| -pattern DtSock = DirType (CONST_DT_SOCK) |
106 |
| - |
107 |
| -pattern DtWht :: DirType |
108 |
| -pattern DtWht = DirType (CONST_DT_WHT) |
| 100 | + deriving Eq |
| 101 | + |
| 102 | +-- | The 'DirType' refers to an entry of unknown type. |
| 103 | +pattern UnknownType :: DirType |
| 104 | +pattern UnknownType = DirType CONST_DT_UNKNOWN |
| 105 | + |
| 106 | +-- | The 'DirType' refers to an entry that is a named pipe. |
| 107 | +pattern NamedPipeType :: DirType |
| 108 | +pattern NamedPipeType = DirType CONST_DT_FIFO |
| 109 | + |
| 110 | +-- | The 'DirType' refers to an entry that is a character device. |
| 111 | +pattern CharacterDeviceType :: DirType |
| 112 | +pattern CharacterDeviceType = DirType CONST_DT_CHR |
| 113 | + |
| 114 | +-- | The 'DirType' refers to an entry that is a directory. |
| 115 | +pattern DirectoryType :: DirType |
| 116 | +pattern DirectoryType = DirType CONST_DT_DIR |
| 117 | + |
| 118 | +-- | The 'DirType' refers to an entry that is a block device. |
| 119 | +pattern BlockDeviceType :: DirType |
| 120 | +pattern BlockDeviceType = DirType CONST_DT_BLK |
| 121 | + |
| 122 | +-- | The 'DirType' refers to an entry that is a regular file. |
| 123 | +pattern RegularFileType :: DirType |
| 124 | +pattern RegularFileType = DirType CONST_DT_REG |
| 125 | + |
| 126 | +-- | The 'DirType' refers to an entry that is a symbolic link. |
| 127 | +pattern SymbolicLinkType :: DirType |
| 128 | +pattern SymbolicLinkType = DirType CONST_DT_LNK |
| 129 | + |
| 130 | +-- | The 'DirType' refers to an entry that is a socket. |
| 131 | +pattern SocketType :: DirType |
| 132 | +pattern SocketType = DirType CONST_DT_SOCK |
| 133 | + |
| 134 | +-- | The 'DirType' refers to an entry that is a whiteout. |
| 135 | +pattern WhiteoutType :: DirType |
| 136 | +pattern WhiteoutType = DirType CONST_DT_WHT |
| 137 | + |
| 138 | +-- | Checks if this 'DirType' refers to an entry of unknown type. |
| 139 | +isUnknownType :: DirType -> Bool |
| 140 | +-- | Checks if this 'DirType' refers to a block device entry. |
| 141 | +isBlockDeviceType :: DirType -> Bool |
| 142 | +-- | Checks if this 'DirType' refers to a character device entry. |
| 143 | +isCharacterDeviceType :: DirType -> Bool |
| 144 | +-- | Checks if this 'DirType' refers to a named pipe entry. |
| 145 | +isNamedPipeType :: DirType -> Bool |
| 146 | +-- | Checks if this 'DirType' refers to a regular file entry. |
| 147 | +isRegularFileType :: DirType -> Bool |
| 148 | +-- | Checks if this 'DirType' refers to a directory entry. |
| 149 | +isDirectoryType :: DirType -> Bool |
| 150 | +-- | Checks if this 'DirType' refers to a symbolic link entry. |
| 151 | +isSymbolicLinkType :: DirType -> Bool |
| 152 | +-- | Checks if this 'DirType' refers to a socket entry. |
| 153 | +isSocketType :: DirType -> Bool |
| 154 | +-- | Checks if this 'DirType' refers to a whiteout entry. |
| 155 | +isWhiteoutType :: DirType -> Bool |
| 156 | + |
| 157 | +isUnknownType dtype = dtype == UnknownType |
| 158 | +isBlockDeviceType dtype = dtype == BlockDeviceType |
| 159 | +isCharacterDeviceType dtype = dtype == CharacterDeviceType |
| 160 | +isNamedPipeType dtype = dtype == NamedPipeType |
| 161 | +isRegularFileType dtype = dtype == RegularFileType |
| 162 | +isDirectoryType dtype = dtype == DirectoryType |
| 163 | +isSymbolicLinkType dtype = dtype == SymbolicLinkType |
| 164 | +isSocketType dtype = dtype == SocketType |
| 165 | +isWhiteoutType dtype = dtype == WhiteoutType |
109 | 166 |
|
110 | 167 | -- | Call @fdopendir@ to obtain a directory stream for @fd@. @fd@ must not be
|
111 | 168 | -- otherwise used after this.
|
|
0 commit comments