easy-file 0.1.1 → 0.2.5
raw patch · 5 files changed
Files
- System/EasyFile.hs +3/−6
- System/EasyFile/Directory.hs +4/−2
- System/EasyFile/Missing.hs +50/−9
- easy-file.cabal +46/−9
- test/Test.hs +31/−0
System/EasyFile.hs view
@@ -36,12 +36,6 @@ * Necessary functions in "System.Directory" and "System.FilePath". -This is alpha version. The specification would be changed in the-future. Please send comments to:--@- <http://github.com/kazu-yamamoto/easy-file/issues>-@ -} module System.EasyFile (@@ -80,6 +74,9 @@ , getChangeTime , getModificationTime , getAccessTime+ -- * Size+ , getFileSize+ , setFileSize -- * File\/directory information , isSymlink , getLinkCount
System/EasyFile/Directory.hs view
@@ -34,8 +34,10 @@ , copyPermissions ) +#if !MIN_VERSION_base(4,8,0) import Control.Applicative-import qualified Control.Exception as E +#endif+import qualified Control.Exception as E import System.Environment ----------------------------------------------------------------@@ -97,7 +99,7 @@ -} getHomeDirectory2 :: IO (Maybe FilePath)-getHomeDirectory2 = (Just . fixPath <$> getEnv "HOME") `E.catch` +getHomeDirectory2 = (Just . fixPath <$> getEnv "HOME") `E.catch` \(_ :: E.IOException) -> return Nothing {- | Returns the pathname of a directory in which application-specific
System/EasyFile/Missing.hs view
@@ -4,14 +4,19 @@ ---------------------------------------------------------------- +#if !MIN_VERSION_base(4,8,0) import Control.Applicative+#endif import Data.Time import Data.Time.Clock.POSIX+import Data.Word (Word64) #if defined(mingw32_HOST_OS) || defined(__MINGW32__)+import Control.Exception import System.Win32.File import System.Win32.Time+import System.Win32.Types (HANDLE) #else-import System.Posix.Files+import System.Posix.Files as P import System.Posix.Types #endif @@ -65,7 +70,7 @@ #endif {-|-The 'getCreationTime' operation returns the+The 'getChangeTime' operation returns the UTC time at which the file or directory was changed. The time is only available on Unix and Mac. Note that Unix's rename() does not change ctime but@@ -116,6 +121,16 @@ ---------------------------------------------------------------- #if defined(mingw32_HOST_OS) || defined(__MINGW32__)+-- Open a file or directory for getting the file metadata.+withFileForInfo :: FilePath -> (HANDLE -> IO a) -> IO a+withFileForInfo file = bracket setup teardown+ where+ setup = createFile file 0 fILE_SHARE_READ Nothing+ oPEN_EXISTING fILE_FLAG_BACKUP_SEMANTICS Nothing+ teardown = closeHandle+#endif++#if defined(mingw32_HOST_OS) || defined(__MINGW32__) creationTime :: (UTCTime,UTCTime,UTCTime) -> UTCTime creationTime (ctime,_,_) = ctime @@ -126,13 +141,11 @@ writeTime (_,_,wtime) = wtime fileTime :: FilePath -> IO (UTCTime,UTCTime,UTCTime)-fileTime file = do- fh <- createFile file gENERIC_READ fILE_SHARE_READ Nothing oPEN_EXISTING fILE_ATTRIBUTE_NORMAL Nothing- (ctime,atime,mtime) <- getFileTime fh- closeHandle fh- return (filetimeToUTCTime ctime- ,filetimeToUTCTime atime- ,filetimeToUTCTime mtime)+fileTime file = withFileForInfo file $ \fh -> do+ (ctime,atime,mtime) <- getFileTime fh+ return (filetimeToUTCTime ctime+ ,filetimeToUTCTime atime+ ,filetimeToUTCTime mtime) {- http://support.microsoft.com/kb/167296/en-us@@ -148,4 +161,32 @@ #else epochTimeToUTCTime :: EpochTime -> UTCTime epochTimeToUTCTime = posixSecondsToUTCTime . realToFrac+#endif++-- | Getting the size of the file.+--+-- Since: 0.2.0.+getFileSize :: FilePath -> IO Word64+#if defined(mingw32_HOST_OS) || defined(__MINGW32__)+getFileSize file = withFileForInfo file $ \fh ->+ fromIntegral . bhfiSize <$> getFileInformationByHandle fh+#else+getFileSize file = fromIntegral . fileSize <$> getFileStatus file+#endif++-- | Setting the size of the file.+--+-- Since: 0.2.4.+setFileSize :: FilePath -> Word64 -> IO ()+#if (defined(mingw32_HOST_OS) || defined(__MINGW32__))+# if MIN_VERSION_Win32(2, 6, 2)+setFileSize file siz = do+ hdl <- createFile file gENERIC_WRITE fILE_SHARE_NONE Nothing oPEN_EXISTING fILE_ATTRIBUTE_NORMAL Nothing+ _ <- setFilePointerEx hdl (fromIntegral siz) fILE_CURRENT+ setEndOfFile hdl+# else+setFileSize _ _ = error "GHC 8.10.5 or earlier does not provide setFilePointerEx"+# endif+#else+setFileSize file siz = P.setFileSize file $ fromIntegral siz #endif
easy-file.cabal view
@@ -1,29 +1,66 @@+Cabal-Version: >= 1.10 Name: easy-file-Version: 0.1.1+Version: 0.2.5 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3 License-File: LICENSE Synopsis: Cross-platform File handling-Description: Cross-platform File handling for Unix/Mac/Windows+Description: Cross-platform File handling for Unix\/Mac\/Windows Homepage: http://github.com/kazu-yamamoto/easy-file Category: System-Cabal-Version: >= 1.6 Build-Type: Simple-Tested-with: GHC == 7.6.1 +Tested-With:+ GHC == 9.6.0+ GHC == 9.4.4+ GHC == 9.2.7+ GHC == 9.0.2+ GHC == 8.10.7+ GHC == 8.8.4+ GHC == 8.6.5+ GHC == 8.4.4+ GHC == 8.2.2+ GHC == 8.0.2+ GHC == 7.10.3+ GHC == 7.8.4+ GHC == 7.6.3+ GHC == 7.4.2+ GHC == 7.0.4+ Library- GHC-Options: -Wall Exposed-Modules: System.EasyFile Other-Modules: System.EasyFile.FilePath System.EasyFile.Directory System.EasyFile.Missing- Build-Depends: base >= 4 && < 5+ Build-Depends:+ base >= 4 && < 5+ , directory+ , filepath+ , time+ if os(windows)- Build-Depends: Win32, time, directory, filepath+ Build-Depends: Win32 else- Build-Depends: unix, time, directory, filepath+ Build-Depends: unix + Default-Language: Haskell2010+ GHC-Options: -Wall+ if impl(ghc >= 8)+ GHC-Options: -Wcompat+++Test-Suite test+ Type: exitcode-stdio-1.0+ Hs-Source-Dirs: test+ Main-Is: Test.hs+ Build-Depends:+ base+ , easy-file+ , tasty+ , tasty-hunit+ Default-Language: Haskell2010+ Source-Repository head Type: git- Location: git://github.com/kazu-yamamoto/easy-file.git+ Location: https://github.com/kazu-yamamoto/easy-file.git
+ test/Test.hs view
@@ -0,0 +1,31 @@+{-# LANGUAGE CPP #-}++module Main where++import System.EasyFile+import Test.Tasty+import Test.Tasty.HUnit++main :: IO ()+main = defaultMain $+ testCase "easy-file tests" $ do++ assertEqual "Test that '/' is path separator"+ ("foo" </> "bar")+ "foo/bar"++ isRelative "foo" @?= True++ isRelative "/foo" @?= isWindows++ isRelative "c:foo" @?= True++ isRelative "c:/foo" @?= not isWindows++isWindows :: Bool+isWindows =+#if defined(mingw32_HOST_OS) || defined(__MINGW32__)+ True+#else+ False+#endif