Skip to content

Commit 25b0f11

Browse files
committed
Add statx
1 parent 76f3422 commit 25b0f11

File tree

11 files changed

+1112
-15
lines changed

11 files changed

+1112
-15
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ jobs:
1616
fail-fast: true
1717
matrix:
1818
os: [ubuntu-22.04, macOS-latest]
19-
ghc: ['9.6', '9.4', '9.2', '9.0', '8.10', '8.8', '8.6', '8.4', '8.2']
19+
ghc: ['9.6', '9.4', '9.2', '9.0', '8.10', '8.8', '8.6']
2020
steps:
2121
- uses: actions/checkout@v3
22-
- name: Install prerequisites for GHC 8.2 on ubuntu-22.04
23-
if: runner.os == 'Linux' && matrix.ghc == '8.2'
24-
run: |
25-
sudo apt-get install libncurses5 libtinfo5
2622
- name: Setup toolchain
2723
run: |
2824
which ghcup

System/Posix/Files.hsc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE Safe #-}
22
{-# LANGUAGE CApiFFI #-}
3+
{-# LANGUAGE PatternSynonyms #-}
34

45
-----------------------------------------------------------------------------
56
-- |
@@ -62,6 +63,69 @@ module System.Posix.Files (
6263
fileBlockSize,
6364
fileBlocks,
6465

66+
-- * Extended file status
67+
ExtendedFileStatus(..),
68+
CAttributes(..),
69+
-- ** Obtaining extended file status
70+
getExtendedFileStatus,
71+
-- ** Flags
72+
StatxFlags(..),
73+
defaultStatxFlags,
74+
pattern EmptyPath,
75+
pattern NoAutoMount,
76+
pattern SymlinkNoFollow,
77+
pattern SyncAsStat,
78+
pattern ForceSync,
79+
pattern DontSync,
80+
-- ** Mask
81+
StatxMask(..),
82+
defaultStatxMask,
83+
pattern StatxType,
84+
pattern StatxMode,
85+
pattern StatxNlink,
86+
pattern StatxUid,
87+
pattern StatxGid,
88+
pattern StatxAtime,
89+
pattern StatxMtime,
90+
pattern StatxCtime,
91+
pattern StatxIno,
92+
pattern StatxSize,
93+
pattern StatxBlocks,
94+
pattern StatxBasicStats,
95+
pattern StatxBtime,
96+
pattern StatxMntId,
97+
pattern StatxAll,
98+
-- ** Querying extended file status
99+
fileBlockSizeX,
100+
linkCountX,
101+
fileOwnerX,
102+
fileGroupX,
103+
fileModeX,
104+
fileIDX,
105+
fileSizeX,
106+
fileBlocksX,
107+
accessTimeHiResX,
108+
creationTimeHiResX,
109+
statusChangeTimeHiResX,
110+
modificationTimeHiResX,
111+
deviceIDX,
112+
specialDeviceIDX,
113+
mountIDX,
114+
fileCompressedX,
115+
fileImmutableX,
116+
fileAppendX,
117+
fileNoDumpX,
118+
fileEncryptedX,
119+
fileVerityX,
120+
fileDaxX,
121+
isBlockDeviceX,
122+
isCharacterDeviceX,
123+
isNamedPipeX,
124+
isRegularFileX,
125+
isDirectoryX,
126+
isSymbolicLinkX,
127+
isSocketX,
128+
65129
-- * Creation
66130
createNamedPipe,
67131
createDevice,
@@ -189,6 +253,25 @@ getFileStatus path = do
189253
throwErrnoPathIfMinus1Retry_ "getFileStatus" path (c_stat s p)
190254
return (FileStatus fp)
191255

256+
-- | Gets extended file status information.
257+
--
258+
-- The target file to open is identified in one of the following ways:
259+
--
260+
-- - If @pathname@ begins with a slash, then it is an absolute pathname that identifies the target file. In this case, @dirfd@ is ignored
261+
-- - If @pathname@ is a string that begins with a character other than a slash and @dirfd@ is a file descriptor that refers to a
262+
-- directory, then pathname is a relative pathname that is interpreted relative to the directory referred to by dirfd.
263+
-- (See @openat(2)@ for an explanation of why this is useful.)
264+
-- - If @pathname@ is an empty string and the 'EmptyPath' flag is specified in flags (see below), then the target file is
265+
-- the one referred to by the file descriptor @dirfd@.
266+
--
267+
-- Note: calls @statx@.
268+
getExtendedFileStatus :: Maybe Fd -- ^ Optional directory file descriptor (@dirfd@)
269+
-> FilePath -- ^ @pathname@ to open
270+
-> StatxFlags -- ^ flags
271+
-> StatxMask -- ^ mask
272+
-> IO ExtendedFileStatus
273+
getExtendedFileStatus mfd path flags masks = withFilePath path $ \s -> getExtendedFileStatus_ mfd s flags masks
274+
192275
-- | Acts as 'getFileStatus' except when the 'FilePath' refers to a symbolic
193276
-- link. In that case the @FileStatus@ information of the symbolic link itself
194277
-- is returned instead of that of the file it points to.

System/Posix/Files/ByteString.hsc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE Safe #-}
22
{-# LANGUAGE CApiFFI #-}
3+
{-# LANGUAGE PatternSynonyms #-}
34

45
-----------------------------------------------------------------------------
56
-- |
@@ -62,6 +63,69 @@ module System.Posix.Files.ByteString (
6263
fileBlockSize,
6364
fileBlocks,
6465

66+
-- * Extended file status
67+
ExtendedFileStatus(..),
68+
CAttributes(..),
69+
-- ** Obtaining extended file status
70+
getExtendedFileStatus,
71+
-- ** Flags
72+
StatxFlags(..),
73+
defaultStatxFlags,
74+
pattern EmptyPath,
75+
pattern NoAutoMount,
76+
pattern SymlinkNoFollow,
77+
pattern SyncAsStat,
78+
pattern ForceSync,
79+
pattern DontSync,
80+
-- ** Mask
81+
StatxMask(..),
82+
defaultStatxMask,
83+
pattern StatxType,
84+
pattern StatxMode,
85+
pattern StatxNlink,
86+
pattern StatxUid,
87+
pattern StatxGid,
88+
pattern StatxAtime,
89+
pattern StatxMtime,
90+
pattern StatxCtime,
91+
pattern StatxIno,
92+
pattern StatxSize,
93+
pattern StatxBlocks,
94+
pattern StatxBasicStats,
95+
pattern StatxBtime,
96+
pattern StatxMntId,
97+
pattern StatxAll,
98+
-- ** Querying extended file status
99+
fileBlockSizeX,
100+
linkCountX,
101+
fileOwnerX,
102+
fileGroupX,
103+
fileModeX,
104+
fileIDX,
105+
fileSizeX,
106+
fileBlocksX,
107+
accessTimeHiResX,
108+
creationTimeHiResX,
109+
statusChangeTimeHiResX,
110+
modificationTimeHiResX,
111+
deviceIDX,
112+
specialDeviceIDX,
113+
mountIDX,
114+
fileCompressedX,
115+
fileImmutableX,
116+
fileAppendX,
117+
fileNoDumpX,
118+
fileEncryptedX,
119+
fileVerityX,
120+
fileDaxX,
121+
isBlockDeviceX,
122+
isCharacterDeviceX,
123+
isNamedPipeX,
124+
isRegularFileX,
125+
isDirectoryX,
126+
isSymbolicLinkX,
127+
isSocketX,
128+
65129
-- * Creation
66130
createNamedPipe,
67131
createDevice,
@@ -184,6 +248,25 @@ getFileStatus path = do
184248
throwErrnoPathIfMinus1Retry_ "getFileStatus" path (c_stat s p)
185249
return (FileStatus fp)
186250

251+
-- | Gets extended file status information.
252+
--
253+
-- The target file to open is identified in one of the following ways:
254+
--
255+
-- - If @pathname@ begins with a slash, then it is an absolute pathname that identifies the target file. In this case, @dirfd@ is ignored
256+
-- - If @pathname@ is a string that begins with a character other than a slash and @dirfd@ is a file descriptor that refers to a
257+
-- directory, then pathname is a relative pathname that is interpreted relative to the directory referred to by dirfd.
258+
-- (See @openat(2)@ for an explanation of why this is useful.)
259+
-- - If @pathname@ is an empty string and the 'EmptyPath' flag is specified in flags (see below), then the target file is
260+
-- the one referred to by the file descriptor @dirfd@.
261+
--
262+
-- Note: calls @statx@.
263+
getExtendedFileStatus :: Maybe Fd -- ^ Optional directory file descriptor (@dirfd@)
264+
-> RawFilePath -- ^ @pathname@ to open
265+
-> StatxFlags -- ^ flags
266+
-> StatxMask -- ^ mask
267+
-> IO ExtendedFileStatus
268+
getExtendedFileStatus mfd path flags masks = withFilePath path $ \s -> getExtendedFileStatus_ mfd s flags masks
269+
187270
-- | Acts as 'getFileStatus' except when the 'RawFilePath' refers to a symbolic
188271
-- link. In that case the @FileStatus@ information of the symbolic link itself
189272
-- is returned instead of that of the file it points to.

0 commit comments

Comments
 (0)