From bd54e9a5f7ea6fb7f0af4d62cfe5048f3748b279 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 21 May 2013 11:45:37 -0400 Subject: [PATCH] better nukeFile This fixes a bug where a direct mode sync fails to delete broken symlinks. --- Utility/Directory.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Utility/Directory.hs b/Utility/Directory.hs index 9477ad5b9a..0a7690b445 100644 --- a/Utility/Directory.hs +++ b/Utility/Directory.hs @@ -5,6 +5,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE CPP #-} + module Utility.Directory where import System.IO.Error @@ -85,9 +87,14 @@ moveFile src dest = tryIO (rename src dest) >>= onrename (Left _) -> return False (Right s) -> return $ isDirectory s -{- Removes a file, which may or may not exist. +{- Removes a file, which may or may not exist, and does not have to + - be a regular file. - - Note that an exception is thrown if the file exists but - cannot be removed. -} nukeFile :: FilePath -> IO () -nukeFile file = whenM (doesFileExist file) $ removeFile file +#ifndef mingw32_HOST_OS +nukeFile = removeLink +#else +nukeFile = removeFile +#endif