1 Commits

Author SHA1 Message Date
b965635d05 Update travis with osc build 2020-04-14 00:00:42 +02:00
19 changed files with 42 additions and 101 deletions

View File

@@ -32,8 +32,8 @@ matrix:
before_install: before_install:
- sudo apt-get install -y hscolour - sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH - export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=3.0 GHCVER=8.8.3 - env: CABALVER=3.0 GHCVER=8.8.1
addons: {apt: {packages: [cabal-install-3.0,ghc-8.8.3], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-3.0,ghc-8.8.1], sources: [hvr-ghc]}}
before_install: before_install:
- sudo apt-get install -y hscolour - sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH - export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
@@ -52,7 +52,7 @@ matrix:
- export PATH=~/.cabal/bin:~/.ghcup/bin:$PATH - export PATH=~/.cabal/bin:~/.ghcup/bin:$PATH
- ghcup install 8.6.5 - ghcup install 8.6.5
- ghcup set 8.6.5 - ghcup set 8.6.5
- ghcup install-cabal 3.2.0.0 - ghcup install-cabal
allow_failures: allow_failures:
- env: CABALVER=head GHCVER=head - env: CABALVER=head GHCVER=head

View File

@@ -1,17 +1,5 @@
# Revision history for hpath-directory # Revision history for hpath-directory
## 0.13.4 -- 2020-05-08
* Add getDirsFilesStream and use streamly-posix for dircontents (#34)
## 0.13.3 -- 2020-04-14
* Fix tests on mac
## 0.13.2 -- 2020-02-17
* Fix bug in `createDirRecursive` with trailing path separators
## 0.13.1 -- 2020-01-29 ## 0.13.1 -- 2020-01-29
* Split some functionality out into 'hpath-posix' * Split some functionality out into 'hpath-posix'

View File

@@ -1,7 +1,7 @@
cabal-version: >=1.10 cabal-version: >=1.10
name: hpath-directory name: hpath-directory
version: 0.13.4 version: 0.13.1
synopsis: Alternative to 'directory' package with ByteString based filepaths synopsis: Alternative to 'directory' package with ByteString based filepaths
description: This provides a safer alternative to the 'directory' description: This provides a safer alternative to the 'directory'
package. FilePaths are ByteString based, so this package. FilePaths are ByteString based, so this
@@ -43,10 +43,8 @@ library
, hpath-posix >= 0.13 , hpath-posix >= 0.13
, safe-exceptions >= 0.1 , safe-exceptions >= 0.1
, streamly >= 0.7 , streamly >= 0.7
, streamly-bytestring >= 0.1.2 , streamly-bytestring >= 0.1.0.1
, streamly-posix >= 0.1.0.1
, time >= 1.8 , time >= 1.8
, transformers
, unix >= 2.5 , unix >= 2.5
, unix-bytestring >= 0.3 , unix-bytestring >= 0.3
, utf8-string , utf8-string

View File

@@ -27,8 +27,7 @@
-- Import as: -- Import as:
-- > import System.Posix.RawFilePath.Directory -- > import System.Posix.RawFilePath.Directory
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-} -- streamly
module System.Posix.RawFilePath.Directory module System.Posix.RawFilePath.Directory
( (
@@ -83,7 +82,6 @@ module System.Posix.RawFilePath.Directory
-- * Directory reading -- * Directory reading
, getDirsFiles , getDirsFiles
, getDirsFiles' , getDirsFiles'
, getDirsFilesStream
-- * Filetype operations -- * Filetype operations
, getFileType , getFileType
-- * Others -- * Others
@@ -95,11 +93,8 @@ where
import Control.Applicative ( (<$>) ) import Control.Applicative ( (<$>) )
import Control.Exception.Safe ( IOException import Control.Exception.Safe ( IOException
, MonadCatch
, MonadMask
, bracket , bracket
, bracketOnError , bracketOnError
, onException
, throwIO , throwIO
, finally , finally
) )
@@ -110,7 +105,6 @@ import Control.Monad ( unless
import Control.Monad.Catch ( MonadThrow(..) ) import Control.Monad.Catch ( MonadThrow(..) )
import Control.Monad.Fail ( MonadFail ) import Control.Monad.Fail ( MonadFail )
import Control.Monad.IfElse ( unlessM ) import Control.Monad.IfElse ( unlessM )
import Control.Monad.IO.Class ( liftIO )
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import Data.ByteString ( ByteString ) import Data.ByteString ( ByteString )
import Data.Traversable ( for ) import Data.Traversable ( for )
@@ -161,8 +155,6 @@ import Streamly
import Streamly.External.ByteString import Streamly.External.ByteString
import qualified Streamly.External.ByteString.Lazy import qualified Streamly.External.ByteString.Lazy
as SL as SL
import qualified Streamly.External.Posix.DirStream
as SD
import qualified Streamly.Data.Fold as FL import qualified Streamly.Data.Fold as FL
import Streamly.Memory.Array import Streamly.Memory.Array
import qualified Streamly.FileSystem.Handle as FH import qualified Streamly.FileSystem.Handle as FH
@@ -572,7 +564,7 @@ easyCopy from to cm rm = do
-- --
-- Throws: -- Throws:
-- --
-- - `InappropriateType` or `PermissionDenied` for wrong file type (directory) -- - `InappropriateType` for wrong file type (directory)
-- - `NoSuchThing` if the file does not exist -- - `NoSuchThing` if the file does not exist
-- - `PermissionDenied` if the directory cannot be read -- - `PermissionDenied` if the directory cannot be read
-- --
@@ -750,8 +742,8 @@ createDirRecursive fm p = go p
| en == eEXIST | en == eEXIST
-> unlessM (doesDirectoryExist dest) (ioError e) -> unlessM (doesDirectoryExist dest) (ioError e)
| en == eNOENT | en == eNOENT
-> go (takeDirectory $ dropTrailingPathSeparator dest) -> createDirRecursive fm (takeDirectory dest)
>> createDir fm dest >> createDirectory dest fm
| otherwise | otherwise
-> ioError e -> ioError e
@@ -1155,17 +1147,11 @@ getDirsFiles p = do
-- of prepending the base path. -- of prepending the base path.
getDirsFiles' :: RawFilePath -- ^ dir to read getDirsFiles' :: RawFilePath -- ^ dir to read
-> IO [RawFilePath] -> IO [RawFilePath]
getDirsFiles' fp = getDirsFilesStream fp >>= S.toList getDirsFiles' fp = do
fd <- openFd fp SPI.ReadOnly [SPDF.oNofollow] Nothing
rawContents <- getDirectoryContents' fd
-- | Like 'getDirsFiles'', except returning a Stream. fmap catMaybes $ for rawContents $ \(_, f) ->
getDirsFilesStream :: (MonadCatch m, MonadAsync m, MonadMask m) if FP.isSpecialDirectoryEntry f then pure Nothing else pure $ Just f
=> RawFilePath
-> IO (SerialT m RawFilePath)
getDirsFilesStream fp = do
fd <- openFd fp SPI.ReadOnly [SPDF.oNofollow] Nothing
ds <- SPDT.fdOpendir fd `onException` SPI.closeFd fd
pure $ fmap snd $ SD.dirContentsStream ds

View File

@@ -8,9 +8,6 @@ import Test.Hspec.Formatters
import qualified Spec import qualified Spec
import Utils import Utils
import System.Posix.Temp.ByteString (mkdtemp) import System.Posix.Temp.ByteString (mkdtemp)
import System.Posix.Env.ByteString (getEnvDefault)
import System.Posix.FilePath ((</>))
import "hpath-directory" System.Posix.RawFilePath.Directory
-- TODO: chardev, blockdev, namedpipe, socket -- TODO: chardev, blockdev, namedpipe, socket
@@ -18,8 +15,7 @@ import "hpath-directory" System.Posix.RawFilePath.Directory
main :: IO () main :: IO ()
main = do main = do
tmpdir <- getEnvDefault "TMPDIR" "/tmp" >>= canonicalizePath tmpBase <- mkdtemp "/tmp/"
tmpBase <- mkdtemp (tmpdir </> "hpath-directory")
writeIORef baseTmpDir (Just (tmpBase `BS.append` "/")) writeIORef baseTmpDir (Just (tmpBase `BS.append` "/"))
putStrLn $ ("Temporary test directory at: " ++ show tmpBase) putStrLn $ ("Temporary test directory at: " ++ show tmpBase)
hspecWith hspecWith

View File

@@ -125,7 +125,7 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
"outputDir" "outputDir"
Strict Strict
CollectFailures CollectFailures
(system $ "diff -r " (system $ "diff -r --no-dereference "
++ toString tmpDir' ++ "inputDir" ++ " " ++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir" ++ toString tmpDir' ++ "outputDir"
++ " >/dev/null") ++ " >/dev/null")

View File

@@ -104,7 +104,7 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
"outputDir" "outputDir"
Overwrite Overwrite
FailEarly FailEarly
(system $ "diff -r " (system $ "diff -r --no-dereference "
++ toString tmpDir' ++ "inputDir" ++ " " ++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir" ++ toString tmpDir' ++ "outputDir"
++ " >/dev/null") ++ " >/dev/null")
@@ -113,7 +113,7 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
it "copyDirRecursive (Overwrite, FailEarly), destination dir already exists" $ do it "copyDirRecursive (Overwrite, FailEarly), destination dir already exists" $ do
tmpDir' <- getRawTmpDir tmpDir' <- getRawTmpDir
(system $ "diff -r " (system $ "diff -r --no-dereference "
++ toString tmpDir' ++ "inputDir" ++ " " ++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "alreadyExistsD" ++ toString tmpDir' ++ "alreadyExistsD"
++ " >/dev/null") ++ " >/dev/null")
@@ -122,7 +122,7 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
"alreadyExistsD" "alreadyExistsD"
Overwrite Overwrite
FailEarly FailEarly
(system $ "diff -r " (system $ "diff -r --no-dereference "
++ toString tmpDir' ++ "inputDir" ++ " " ++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "alreadyExistsD" ++ toString tmpDir' ++ "alreadyExistsD"
++ " >/dev/null") ++ " >/dev/null")

View File

@@ -89,7 +89,7 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
"outputDir" "outputDir"
Strict Strict
FailEarly FailEarly
(system $ "diff -r " (system $ "diff -r --no-dereference "
++ toString tmpDir' ++ "inputDir" ++ " " ++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir" ++ toString tmpDir' ++ "outputDir"
++ " >/dev/null") ++ " >/dev/null")

View File

@@ -49,11 +49,6 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
createDirRecursive' "newDir" createDirRecursive' "newDir"
deleteDir' "newDir" deleteDir' "newDir"
it "createDirRecursive with trailing path separator, all fine" $ do
createDirRecursive' "newDir/foo/"
deleteDir' "newDir/foo"
deleteDir' "newDir"
it "createDirRecursive, parent directories do not exist" $ do it "createDirRecursive, parent directories do not exist" $ do
createDirRecursive' "some/thing/dada" createDirRecursive' "some/thing/dada"
deleteDir' "some/thing/dada" deleteDir' "some/thing/dada"

View File

@@ -70,7 +70,7 @@ spec = beforeAll_ (upTmpDir >> setupFiles) $ afterAll_ cleanupFiles $
it "deleteFile, wrong file type (directory)" $ it "deleteFile, wrong file type (directory)" $
deleteFile' "dir" deleteFile' "dir"
`shouldThrow` `shouldThrow`
(\e -> ioeGetErrorType e == InappropriateType || ioeGetErrorType e == PermissionDenied) (\e -> ioeGetErrorType e == InappropriateType)
it "deleteFile, file does not exist" $ it "deleteFile, file does not exist" $
deleteFile' "doesNotExist" deleteFile' "doesNotExist"

View File

@@ -1,9 +1,5 @@
# Revision history for hpath-io # Revision history for hpath-io
## 0.13.2 -- 2020-05-08
* Add getDirsFilesStream and use streamly-posix for dircontents (#34)
## 0.13.0 -- 2020-01-26 ## 0.13.0 -- 2020-01-26
* switch to using 'hpath-bytestring' for the implementation (this is now just a wrapper module, mostly) * switch to using 'hpath-bytestring' for the implementation (this is now just a wrapper module, mostly)

View File

@@ -1,5 +1,5 @@
name: hpath-io name: hpath-io
version: 0.13.2 version: 0.13.1
synopsis: High-level IO operations on files/directories synopsis: High-level IO operations on files/directories
description: High-level IO operations on files/directories, utilizing type-safe Paths description: High-level IO operations on files/directories, utilizing type-safe Paths
-- bug-reports: -- bug-reports:

View File

@@ -27,8 +27,7 @@
-- For other functions (like `copyFile`), the behavior on these file types is -- For other functions (like `copyFile`), the behavior on these file types is
-- unreliable/unsafe. Check the documentation of those functions for details. -- unreliable/unsafe. Check the documentation of those functions for details.
{-# LANGUAGE FlexibleContexts #-} -- streamly {-# LANGUAGE PackageImports #-}
{-# LANGUAGE PackageImports #-}
module HPath.IO module HPath.IO
( (
@@ -83,7 +82,6 @@ module HPath.IO
-- * Directory reading -- * Directory reading
, getDirsFiles , getDirsFiles
, getDirsFiles' , getDirsFiles'
, getDirsFilesStream
-- * Filetype operations -- * Filetype operations
, getFileType , getFileType
-- * Others -- * Others
@@ -96,9 +94,7 @@ module HPath.IO
where where
import Control.Exception.Safe ( MonadMask import Control.Exception.Safe ( bracketOnError
, MonadCatch
, bracketOnError
, finally , finally
) )
import Control.Monad.Catch ( MonadThrow(..) ) import Control.Monad.Catch ( MonadThrow(..) )
@@ -765,15 +761,6 @@ getDirsFiles' (Path fp) = do
for rawContents $ \r -> parseRel r for rawContents $ \r -> parseRel r
-- | Like 'getDirsFiles'', except returning a Stream.
getDirsFilesStream :: (MonadCatch m, MonadAsync m, MonadMask m)
=> Path b
-> IO (SerialT m (Path Rel))
getDirsFilesStream (Path fp) = do
s <- RD.getDirsFilesStream fp
pure (s >>= parseRel)
--------------------------- ---------------------------

View File

@@ -1,14 +1,5 @@
# Revision history for hpath-posix # Revision history for hpath-posix
## 0.13.2 -- 2020-04-14 ## 0.1.0.0 -- 2020-01-29
* fix macOS compatibility, especially with memory bug in `fdopendir`
## 0.13.1 -- 2020-02-08
* Remove unnecessary dependencies
## 0.13.0 -- 2020-01-29
* First version. Released on an unsuspecting world. * First version. Released on an unsuspecting world.

View File

@@ -1,7 +1,7 @@
#include "dirutils.h" #include "dirutils.h"
unsigned int unsigned int
__posixdir_d_type(struct dirent* d) __posixdir_d_type(struct dirent* d)
{ {
return(d -> d_type); return(d -> d_type);
} }

View File

@@ -7,9 +7,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
extern unsigned int extern unsigned int
__posixdir_d_type(struct dirent* d) __posixdir_d_type(struct dirent* d)
; ;
#endif #endif

View File

@@ -1,7 +1,7 @@
cabal-version: >=1.10 cabal-version: >=1.10
name: hpath-posix name: hpath-posix
version: 0.13.2 version: 0.13.0
synopsis: Some low-level POSIX glue code, that is not in 'unix' synopsis: Some low-level POSIX glue code, that is not in 'unix'
homepage: https://github.com/hasufell/hpath homepage: https://github.com/hasufell/hpath
bug-reports: https://github.com/hasufell/hpath/issues bug-reports: https://github.com/hasufell/hpath/issues
@@ -32,9 +32,17 @@ library
-- other-extensions: -- other-extensions:
c-sources: cbits/dirutils.c c-sources: cbits/dirutils.c
build-depends: base >= 4.8 && <5 build-depends: base >= 4.8 && <5
, IfElse
, bytestring >= 0.10 , bytestring >= 0.10
, exceptions >= 0.10
, hpath-filepath >= 0.10.3 , hpath-filepath >= 0.10.3
, safe-exceptions >= 0.1
, streamly >= 0.7
, streamly-bytestring >= 0.1.0.1
, time >= 1.8
, unix >= 2.5 , unix >= 2.5
, unix-bytestring >= 0.3
, utf8-string
if impl(ghc < 8.0) if impl(ghc < 8.0)
build-depends: build-depends:
fail >= 4.9 fail >= 4.9

View File

@@ -10,7 +10,6 @@
-- Traversal and read operations on directories. -- Traversal and read operations on directories.
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
@@ -174,15 +173,11 @@ foreign import ccall unsafe "__hscore_d_name"
foreign import ccall unsafe "__posixdir_d_type" foreign import ccall unsafe "__posixdir_d_type"
c_type :: Ptr CDirent -> IO DirType c_type :: Ptr CDirent -> IO DirType
foreign import capi "stdlib.h realpath" foreign import ccall "realpath"
c_realpath :: CString -> CString -> IO CString c_realpath :: CString -> CString -> IO CString
-- Using normal 'ccall' here lead to memory bugs, crashes foreign import ccall unsafe "fdopendir"
-- and corrupted d_name entries. It appears there are two fdopendirs: c_fdopendir :: Posix.Fd -> IO (Ptr ())
-- https://opensource.apple.com/source/Libc/Libc-1244.1.7/include/dirent.h.auto.html
-- The capi call picks the correct one.
foreign import capi unsafe "dirent.h fdopendir"
c_fdopendir :: Posix.Fd -> IO (Ptr CDir)
---------------------------------------------------------- ----------------------------------------------------------
-- less dodgy but still lower-level -- less dodgy but still lower-level

View File

@@ -186,8 +186,11 @@ parseRel filepath =
-- | Parses a path, whether it's relative or absolute. -- | Parses a path, whether it's relative or absolute. Will lose
-- information on whether it's relative or absolute. If you need to know,
-- reparse it.
-- --
-- Filenames must not contain slashes.
-- Excludes '.' and '..'. -- Excludes '.' and '..'.
-- --
-- Throws: 'PathParseException' -- Throws: 'PathParseException'