system-fileio 0.3.10 → 0.3.11
raw patch · 6 files changed
+62/−14 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- lib/Filesystem.hs +14/−12
- lib/hssystemfileio-unix.c +8/−0
- lib/hssystemfileio-unix.h +3/−0
- system-fileio.cabal +4/−2
- tests/FilesystemTests/Posix.hs +31/−0
- tests/system-fileio-tests.cabal +2/−0
lib/Filesystem.hs view
@@ -73,12 +73,6 @@ , rename ) where -#ifndef CABAL_OS_WINDOWS-#if MIN_VERSION_base(4,2,0)-#define SYSTEMFILEIO_LOCAL_OPEN_FILE-#endif-#endif- import Prelude hiding (FilePath, readFile, writeFile, appendFile) import qualified Control.Exception as Exc@@ -118,6 +112,9 @@ import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import qualified System.Posix as Posix import qualified System.Posix.Error as Posix+#if MIN_VERSION_unix(2,5,1)+import qualified System.Posix.Files.ByteString+#endif #endif @@ -158,7 +155,7 @@ #else isDirectory path = Exc.catch (do- stat <- posixStat "isFile" path+ stat <- posixStat "isDirectory" path return (Posix.isDirectory stat)) ((\_ -> return False) :: IOError -> IO Bool) #endif@@ -953,18 +950,23 @@ _ <- throwErrnoPathIfRetry failed loc path io return () +posixStat :: String -> FilePath -> IO Posix.FileStatus+#if MIN_VERSION_unix(2,5,1)+posixStat _ path = System.Posix.Files.ByteString.getFileStatus (R.encode R.posix path)+#else+posixStat loc path = withFd loc path Posix.getFdStatus+ withFd :: String -> FilePath -> (Posix.Fd -> IO a) -> IO a withFd fnName path = Exc.bracket open close where open = withFilePath path $ \cpath -> do- fd <- throwErrnoPathIfMinus1 fnName path (c_open cpath 0)+ fd <- throwErrnoPathIfMinus1 fnName path (c_open_nonblocking cpath 0) return (Posix.Fd fd) close = Posix.closeFd -posixStat :: String -> FilePath -> IO Posix.FileStatus-posixStat loc path = withFd loc path Posix.getFdStatus+foreign import ccall unsafe "hssystemfileio_open_nonblocking"+ c_open_nonblocking :: CString -> CInt -> IO CInt -foreign import ccall unsafe "open"- c_open :: CString -> CInt -> IO CInt+#endif foreign import ccall unsafe "free" c_free :: Ptr a -> IO ()
lib/hssystemfileio-unix.c view
@@ -8,6 +8,7 @@ #include <dirent.h> #include <errno.h>+#include <fcntl.h> #include <stddef.h> #include <stdlib.h> #include <sys/stat.h>@@ -119,4 +120,11 @@ { return rc; } return chmod(new_path, st.st_mode);+}++int+hssystemfileio_open_nonblocking(const char *path, int int_mode)+{+ mode_t mode = int_mode | O_NONBLOCK;+ return open(path, mode); }
lib/hssystemfileio-unix.h view
@@ -24,4 +24,7 @@ int hssystemfileio_copy_permissions(const char *old_path, const char *new_path); +int+hssystemfileio_open_nonblocking(const char *path, int mode);+ #endif
system-fileio.cabal view
@@ -1,5 +1,5 @@ name: system-fileio-version: 0.3.10+version: 0.3.11 license: MIT license-file: license.txt author: John Millikin <jmillikin@gmail.com>@@ -42,7 +42,7 @@ source-repository this type: bazaar location: https://john-millikin.com/branches/system-fileio/0.3/- tag: system-fileio_0.3.9+ tag: system-fileio_0.3.11 library ghc-options: -Wall -O2@@ -65,6 +65,8 @@ build-depends: unix >= 2.3 c-sources: lib/hssystemfileio-unix.c+ if impl(ghc >= 7.2.0) && impl(ghc < 7.4.0)+ cpp-options: -DSYSTEMFILEIO_LOCAL_OPEN_FILE exposed-modules: Filesystem
tests/FilesystemTests/Posix.hs view
@@ -49,6 +49,14 @@ (fromText "\xA1\xA2.txt") , test_IsFile "iso8859" (decode "\xA1\xA2\xA3.txt")+ , suite "pipe"+ [ test_PipeIsFile "ascii"+ (decode "test.txt")+ , test_PipeIsFile "utf8"+ (fromText "\xA1\xA2.txt")+ , test_PipeIsFile "iso8859"+ (decode "\xA1\xA2\xA3.txt")+ ] ] , suite "isDirectory" [ test_IsDirectory "ascii"@@ -249,6 +257,18 @@ after <- liftIO $ Filesystem.isFile path $expect after +test_PipeIsFile :: Text -> FilePath -> Suite+test_PipeIsFile test_name file_name = assertionsWithTemp test_name $ \tmp -> do+ let path = tmp </> file_name+ + before <- liftIO $ Filesystem.isFile path+ $expect (not before)+ + mkfifo_ffi path+ + after <- liftIO $ Filesystem.isFile path+ $expect after+ test_IsDirectory :: Text -> FilePath -> Suite test_IsDirectory test_name dir_name = assertionsWithTemp test_name $ \tmp -> do let path = tmp </> dir_name@@ -635,6 +655,14 @@ $assert (ret == 0) +-- | Create a FIFO using the raw POSIX API, via FFI+mkfifo_ffi :: FilePath -> Assertions ()+mkfifo_ffi path = do+ ret <- liftIO $ withPathCString path $ \path_cstr ->+ c_mkfifo path_cstr 0o700+ + $assert (ret == 0)+ getcwd_ffi :: Assertions FilePath getcwd_ffi = do buf <- liftIO $ c_getcwd nullPtr 0@@ -690,6 +718,9 @@ foreign import ccall unsafe "symlink" c_symlink :: CString -> CString -> IO CInt++foreign import ccall unsafe "mkfifo"+ c_mkfifo :: CString -> CInt -> IO CInt foreign import ccall unsafe "getcwd" c_getcwd :: CString -> CSize -> IO CString
tests/system-fileio-tests.cabal view
@@ -40,3 +40,5 @@ build-depends: unix >= 2.3 && < 2.6 c-sources: ../lib/hssystemfileio-unix.c+ if impl(ghc >= 7.2.0) && impl(ghc < 7.4.0)+ cpp-options: -DSYSTEMFILEIO_LOCAL_OPEN_FILE