{-# LINE 1 "System/Posix/ByteString/FilePath.hsc" #-}{-# LANGUAGE Trustworthy #-}{-# LANGUAGE TypeApplications #-}------------------------------------------------------------------------------- |-- Module : System.Posix.ByteString.FilePath-- Copyright : (c) The University of Glasgow 2002-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org-- Stability : provisional-- Portability : non-portable (requires POSIX)---- Internal stuff: support for ByteString FilePaths-------------------------------------------------------------------------------moduleSystem.Posix.ByteString.FilePath(RawFilePath,withFilePath,peekFilePath,peekFilePathLen,throwErrnoPathIfMinus1Retry,throwErrnoPathIfMinus1Retry_,throwErrnoPathIfNullRetry,throwErrnoPathIfRetry,throwErrnoPath,throwErrnoPathIf,throwErrnoPathIf_,throwErrnoPathIfNull,throwErrnoPathIfMinus1,throwErrnoPathIfMinus1_,throwErrnoTwoPathsIfMinus1_)whereimportForeignhiding(void)importForeign.Chiding(throwErrnoPath,throwErrnoPathIf,throwErrnoPathIf_,throwErrnoPathIfNull,throwErrnoPathIfMinus1,throwErrnoPathIfMinus1_)importControl.MonadimportControl.ExceptionimportData.ByteString.Internal(c_strlen)importGHC.ForeignasGHC(peekCStringLen)importGHC.IO.Encoding(getFileSystemEncoding)importGHC.IO.ExceptionimportData.ByteStringasBimportData.ByteString.Char8asBCimportPreludehiding(FilePath){-# LINE 54 "System/Posix/ByteString/FilePath.hsc" #-}-- | A literal POSIX file pathtypeRawFilePath=ByteStringwithFilePath::RawFilePath->(CString->IOa)->IOawithFilePathpath=useAsCStringSafepathpeekFilePath::CString->IORawFilePathpeekFilePath=packCStringpeekFilePathLen::CStringLen->IORawFilePathpeekFilePathLen=packCStringLenthrowErrnoPathIfMinus1Retry::(Eqa,Numa)=>String->RawFilePath->IOa->IOathrowErrnoPathIfMinus1Retrylocpathf=dothrowErrnoPathIfRetry(==-1)locpathfthrowErrnoPathIfMinus1Retry_::(Eqa,Numa)=>String->RawFilePath->IOa->IO()throwErrnoPathIfMinus1Retry_locpathf=void$throwErrnoPathIfRetry(==-1)locpathfthrowErrnoPathIfNullRetry::String->RawFilePath->IO(Ptra)->IO(Ptra)throwErrnoPathIfNullRetrylocpathf=throwErrnoPathIfRetry(==nullPtr)locpathfthrowErrnoPathIfRetry::(a->Bool)->String->RawFilePath->IOa->IOathrowErrnoPathIfRetryprlocrpathf=dores<-fifprresthendoerr<-getErrnoiferr==eINTRthenthrowErrnoPathIfRetryprlocrpathfelsethrowErrnoPathlocrpathelsereturnres-- | as 'throwErrno', but exceptions include the given path when appropriate.--throwErrnoPath::String->RawFilePath->IOathrowErrnoPathlocpath=doerrno<-getErrnopath'<-either(const(BC.unpackpath))id<$>try@IOException(decodeWithBasePosixpath)ioError(errnoToIOErrorlocerrnoNothing(Justpath'))-- | as 'throwErrnoIf', but exceptions include the given path when-- appropriate.--throwErrnoPathIf::(a->Bool)->String->RawFilePath->IOa->IOathrowErrnoPathIfcondlocpathf=dores<-fifcondresthenthrowErrnoPathlocpathelsereturnres-- | as 'throwErrnoIf_', but exceptions include the given path when-- appropriate.--throwErrnoPathIf_::(a->Bool)->String->RawFilePath->IOa->IO()throwErrnoPathIf_condlocpathf=void$throwErrnoPathIfcondlocpathf-- | as 'throwErrnoIfNull', but exceptions include the given path when-- appropriate.--throwErrnoPathIfNull::String->RawFilePath->IO(Ptra)->IO(Ptra)throwErrnoPathIfNull=throwErrnoPathIf(==nullPtr)-- | as 'throwErrnoIfMinus1', but exceptions include the given path when-- appropriate.--throwErrnoPathIfMinus1::(Eqa,Numa)=>String->RawFilePath->IOa->IOathrowErrnoPathIfMinus1=throwErrnoPathIf(==-1)-- | as 'throwErrnoIfMinus1_', but exceptions include the given path when-- appropriate.--throwErrnoPathIfMinus1_::(Eqa,Numa)=>String->RawFilePath->IOa->IO()throwErrnoPathIfMinus1_=throwErrnoPathIf_(==-1)-- | as 'throwErrnoTwoPathsIfMinus1_', but exceptions include two paths when appropriate.--throwErrnoTwoPathsIfMinus1_::(Eqa,Numa)=>String->RawFilePath->RawFilePath->IOa->IO()throwErrnoTwoPathsIfMinus1_locpath1path2action=dopath1'<-either(const(BC.unpackpath1))id<$>try@IOException(decodeWithBasePosixpath1)path2'<-either(const(BC.unpackpath2))id<$>try@IOException(decodeWithBasePosixpath2)throwErrnoIfMinus1_(loc<>" '"<>path1'<>"' to '"<>path2'<>"'")action-- | This mimics the filepath decoder base uses on unix,-- with the small distinction that we're not truncating at NUL bytes (because we're not at-- the outer FFI layer).decodeWithBasePosix::RawFilePath->IOStringdecodeWithBasePosixba=B.useAsCStringLenba$\fp->peekFilePathPosixfpwherepeekFilePathPosix::CStringLen->IOStringpeekFilePathPosixfp=getFileSystemEncoding>>=\enc->GHC.peekCStringLenencfp-- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are-- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660useAsCStringSafe::RawFilePath->(CString->IOa)->IOauseAsCStringSafepathf=useAsCStringLenpath$\(ptr,len)->doclen<-c_strlenptrifclen==fromIntegrallenthenfptrelsedopath'<-either(const(BC.unpackpath))id<$>try@IOException(decodeWithBasePosixpath)ioError(errpath')whereerrpath'=IOError{ioe_handle=Nothing,ioe_type=InvalidArgument,ioe_location="checkForInteriorNuls",ioe_description="POSIX filepaths must not contain internal NUL octets.",ioe_errno=Nothing,ioe_filename=Justpath'}