Merge branch 'mac-compatibility'

This commit is contained in:
Julian Ospald 2020-04-14 23:45:20 +02:00
commit 3cb17dd253
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
15 changed files with 81 additions and 33 deletions

View File

@ -9,18 +9,50 @@ matrix:
include: include:
- env: CABALVER=3.0 GHCVER=7.10.3 SKIP_DOCTESTS=yes - env: CABALVER=3.0 GHCVER=7.10.3 SKIP_DOCTESTS=yes
addons: {apt: {packages: [cabal-install-3.0,ghc-7.10.3], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-3.0,ghc-7.10.3], sources: [hvr-ghc]}}
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=3.0 GHCVER=8.0.2 SKIP_DOCTESTS=yes - env: CABALVER=3.0 GHCVER=8.0.2 SKIP_DOCTESTS=yes
addons: {apt: {packages: [cabal-install-3.0,ghc-8.0.2], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-3.0,ghc-8.0.2], sources: [hvr-ghc]}}
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=3.0 GHCVER=8.2.2 - env: CABALVER=3.0 GHCVER=8.2.2
addons: {apt: {packages: [cabal-install-3.0,ghc-8.2.2], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-3.0,ghc-8.2.2], sources: [hvr-ghc]}}
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=3.0 GHCVER=8.4.4 - env: CABALVER=3.0 GHCVER=8.4.4
addons: {apt: {packages: [cabal-install-3.0,ghc-8.4.4], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-3.0,ghc-8.4.4], sources: [hvr-ghc]}}
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=3.0 GHCVER=8.6.5 - env: CABALVER=3.0 GHCVER=8.6.5
addons: {apt: {packages: [cabal-install-3.0,ghc-8.6.5], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-3.0,ghc-8.6.5], sources: [hvr-ghc]}}
- env: CABALVER=3.0 GHCVER=8.8.1 before_install:
addons: {apt: {packages: [cabal-install-3.0,ghc-8.8.1], sources: [hvr-ghc]}} - sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=3.0 GHCVER=8.8.3
addons: {apt: {packages: [cabal-install-3.0,ghc-8.8.3], sources: [hvr-ghc]}}
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- env: CABALVER=head GHCVER=head - env: CABALVER=head GHCVER=head
addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}} addons: {apt: {packages: [cabal-install-head,ghc-head], sources: [hvr-ghc]}}
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
- os: osx
osx_image: xcode11.3
language: generic
before_install:
- mkdir -p ~/.ghcup/bin
- curl https://gitlab.haskell.org/haskell/ghcup/raw/master/ghcup > ~/.ghcup/bin/ghcup
- chmod +x ~/.ghcup/bin/ghcup
- export PATH=~/.cabal/bin:~/.ghcup/bin:$PATH
- ghcup install 8.6.5
- ghcup set 8.6.5
- ghcup install-cabal 3.2.0.0
allow_failures: allow_failures:
- env: CABALVER=head GHCVER=head - env: CABALVER=head GHCVER=head
@ -29,10 +61,6 @@ env:
global: global:
- secure: HPBARvNM85ea2U0Ynq5MMe6BRlnuwqXWuSn20VY3EYCAT2njkVPYnR3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mLpNthNvtto7ffHMZrt6fvK9axI+r21VPftf/3FiFY4mnCp/Bln+ijklfZSN71VqiT20EWuqxQHw8aCpT00KA/PKGl9iJfoN4OO3XzNRTtmM+L9Im4bc1ni9YQ6N3UYg3z0nEnCLwFcTmTH/tDMHRremE0dM6B++YfcnyIhen8w+hG4bcXk7jbMUizRhUhStN7TZQuC9S4wE5whhp9c03rJZMmH5E2rlXY3lwVgeyWm1TuMp1RYWI=
before_install:
- sudo apt-get install -y hscolour
- export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
install: install:
- cabal --version - cabal --version
- travis_retry cabal update - travis_retry cabal update
@ -48,7 +76,6 @@ script:
- (cd hpath-filepath && cabal check) - (cd hpath-filepath && cabal check)
- (cd hpath-io && cabal check) - (cd hpath-io && cabal check)
- cabal sdist all - cabal sdist all
- cabal haddock --haddock-hyperlink-source --haddock-html-location=https://hackage.haskell.org/package/\$pkg-\$version/docs/ all
- cabal install --lib all - cabal install --lib all
notifications: notifications:

View File

@ -1,5 +1,9 @@
# Revision history for hpath-directory # Revision history for hpath-directory
## 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.1 version: 0.13.2
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,7 +43,7 @@ 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.0.1 , streamly-bytestring >= 0.1.2
, time >= 1.8 , time >= 1.8
, unix >= 2.5 , unix >= 2.5
, unix-bytestring >= 0.3 , unix-bytestring >= 0.3

View File

@ -564,7 +564,7 @@ easyCopy from to cm rm = do
-- --
-- Throws: -- Throws:
-- --
-- - `InappropriateType` for wrong file type (directory) -- - `InappropriateType` or `PermissionDenied` 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
-- --
@ -742,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
-> createDirRecursive fm (takeDirectory dest) -> go (takeDirectory $ dropTrailingPathSeparator dest)
>> createDirectory dest fm >> createDir fm dest
| otherwise | otherwise
-> ioError e -> ioError e

View File

@ -8,6 +8,9 @@ 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
@ -15,7 +18,8 @@ import System.Posix.Temp.ByteString (mkdtemp)
main :: IO () main :: IO ()
main = do main = do
tmpBase <- mkdtemp "/tmp/" tmpdir <- getEnvDefault "TMPDIR" "/tmp" >>= canonicalizePath
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 --no-dereference " (system $ "diff -r "
++ 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 --no-dereference " (system $ "diff -r "
++ 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 --no-dereference " (system $ "diff -r "
++ 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 --no-dereference " (system $ "diff -r "
++ 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 --no-dereference " (system $ "diff -r "
++ toString tmpDir' ++ "inputDir" ++ " " ++ toString tmpDir' ++ "inputDir" ++ " "
++ toString tmpDir' ++ "outputDir" ++ toString tmpDir' ++ "outputDir"
++ " >/dev/null") ++ " >/dev/null")

View File

@ -49,6 +49,11 @@ 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) (\e -> ioeGetErrorType e == InappropriateType || ioeGetErrorType e == PermissionDenied)
it "deleteFile, file does not exist" $ it "deleteFile, file does not exist" $
deleteFile' "doesNotExist" deleteFile' "doesNotExist"

View File

@ -1,5 +1,14 @@
# Revision history for hpath-posix # Revision history for hpath-posix
## 0.1.0.0 -- 2020-01-29 ## 0.13.2 -- 2020-04-14
* 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,7 +7,9 @@
#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.0 version: 0.13.2
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,17 +32,9 @@ 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,6 +10,7 @@
-- 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 #-}
@ -173,11 +174,15 @@ 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 ccall "realpath" foreign import capi "stdlib.h realpath"
c_realpath :: CString -> CString -> IO CString c_realpath :: CString -> CString -> IO CString
foreign import ccall unsafe "fdopendir" -- Using normal 'ccall' here lead to memory bugs, crashes
c_fdopendir :: Posix.Fd -> IO (Ptr ()) -- and corrupted d_name entries. It appears there are two fdopendirs:
-- 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