首页 > 解决方案 > 如何将haskell中的文件复制到具有“仅附加”权限并保留修改时间的目录

问题描述

我在具有“仅附加”权限的 Windows 上有目标目录。我想将文件复制到它并且我想保留修改时间。下一个代码进行复制但崩溃:

import qualified Data.ByteString.Lazy  as BS
withBinaryFile destPath WriteMode (\h -> do
     hSetBinaryMode h True
     BS.readFile sourcePath >>= BS.hPut h
   )
-- next line crashes due to permission
getModificationTime sourcePath >>= setModificationTime destPath

下一个代码会更好,但是函数hSetModificationTime不存在

import qualified Data.ByteString.Lazy  as BS
withBinaryFile destPath WriteMode (\h -> do
     hSetBinaryMode h True
     BS.readFile sourcePath >>= BS.hPut h
                                        -- not existing function 
     getModificationTime sourcePath >>= hSetModificationTime h

   )

标签: haskellcopyfile-permissionsfile-attributes

解决方案


推荐阅读