X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FDirectory.hs;h=e6b49c2862897be6be6a7469ab72de35ea81a3b7;hb=08b1730186cae35448d2f8f0e1d3f67db5cac01b;hp=fd6774c082b1d3ae25e6f9c8fad9445091138f89;hpb=1e7b1d58aab549ad7efc2b0f33d5b13872c6e004;p=haskell-directory.git diff --git a/System/Directory.hs b/System/Directory.hs index fd6774c..e6b49c2 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -543,26 +543,27 @@ However, it certainly isn't always what you want. copyFile :: FilePath -> FilePath -> IO () copyFile fromFPath toFPath = #if (!(defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ > 600)) - do readFile fromFPath >>= writeFile toFPath - try (copyPermissions fromFPath toFPath) - return () + do readFile fromFPath >>= writeFile toFPath + try (copyPermissions fromFPath toFPath) + return () #else - (bracket (openBinaryFile fromFPath ReadMode) hClose $ \hFrom -> - bracket (openBinaryFile toFPath WriteMode) hClose $ \hTo -> - allocaBytes bufferSize $ \buffer -> do - copyContents hFrom hTo buffer - try (copyPermissions fromFPath toFPath) - return ()) `catch` (ioError . changeFunName) - where - bufferSize = 1024 - - changeFunName (IOError h iot fun str mb_fp) = IOError h iot "copyFile" str mb_fp - - copyContents hFrom hTo buffer = do - count <- hGetBuf hFrom buffer bufferSize - when (count > 0) $ do - hPutBuf hTo buffer count - copyContents hFrom hTo buffer + (bracket (openBinaryFile fromFPath ReadMode) hClose $ \hFrom -> + bracket (openBinaryFile toFPath WriteMode) hClose $ \hTo -> + allocaBytes bufferSize $ \buffer -> do + copyContents hFrom hTo buffer + try (copyPermissions fromFPath toFPath) + return ()) `catch` (ioError . changeFunName) + where + bufferSize = 1024 + + changeFunName (IOError h iot fun str mb_fp) + = IOError h iot "copyFile" str mb_fp + + copyContents hFrom hTo buffer = do + count <- hGetBuf hFrom buffer bufferSize + when (count > 0) $ do + hPutBuf hTo buffer count + copyContents hFrom hTo buffer #endif -- | Given path referring to a file or directory, returns a @@ -861,14 +862,8 @@ isDirectory stat = do return (s_isdir mode) fileNameEndClean :: String -> String -fileNameEndClean name = - if i > 0 && (ec == '\\' || ec == '/') then - fileNameEndClean (take i name) - else - name - where - i = (length name) - 1 - ec = name !! i +fileNameEndClean name = if isDrive name then addTrailingPathSeparator name + else dropTrailingPathSeparator name foreign import ccall unsafe "__hscore_R_OK" r_OK :: CInt foreign import ccall unsafe "__hscore_W_OK" w_OK :: CInt