nobsun #3648(2007/11/01 13:36 GMT) [ Haskell ] Rating0/0=0.00
プログラム(修正版)にまだバグがあった.POSIX系のファイルシステムでは, シンボリックリンクでディレクトリパスに循環があると停止しなくなってしまう.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
module Main (main) where import System.Directory ( setCurrentDirectory, getCurrentDirectory , getDirectoryContents , removeDirectoryRecursive, removeFile ) import System.Posix.Files (getSymbolicLinkStatus, isDirectory) import System.Environment (getArgs) main :: IO () main = getArgs >>= mapM_ cleaning cleaning :: FilePath -> IO () cleaning = (>> removeBackupFiles) . setCurrentDirectory removeBackupFiles :: IO () removeBackupFiles = do { cwd <- getCurrentDirectory ; getDirectoryContents "." >>= mapM_ (rmbk cwd) . drop 2 } rmbk :: FilePath -> FilePath -> IO () rmbk cwd path = do { fstat <- getSymbolicLinkStatus path ; let backup = '~'== last path ; if isDirectory fstat then if backup then removeDirectoryRecursive path else cleaning path >> setCurrentDirectory cwd else if backup then removeFile path else return () }
Rating0/0=0.00-0+
[ reply ]
nobsun
#3648()
[
Haskell
]
Rating0/0=0.00
Rating0/0=0.00-0+