summaryrefslogtreecommitdiff
path: root/Command/Import.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-12-09 13:37:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-12-09 13:43:47 -0400
commit1c806a0a6c593cc6b4fc82ce3ca709ffd495fa86 (patch)
tree72e68ec88100c795fb74491b3ace77c98810b40d /Command/Import.hs
parenta3bf2712c63958fee1e696bc256900763137ed0f (diff)
better handling of overwriting an existing file/directory/broken link when importing
Previous test did not notice if there is a dangling symlink. Also, if a directory exists with the same name as the imported file, that cannot work, so don't let --force have an effect.
Diffstat (limited to 'Command/Import.hs')
-rw-r--r--Command/Import.hs14
1 files changed, 9 insertions, 5 deletions
diff --git a/Command/Import.hs b/Command/Import.hs
index 08960f25a..dcf2b0fa0 100644
--- a/Command/Import.hs
+++ b/Command/Import.hs
@@ -88,16 +88,20 @@ start mode (srcfile, destfile) =
liftIO $ removeFile srcfile
next $ return True
importfile = do
- whenM (liftIO $ doesFileExist destfile) $
- unlessM (Annex.getState Annex.force) $
- error $ "not overwriting existing " ++ destfile ++
- " (use --force to override)"
-
+ handleexisting =<< liftIO (catchMaybeIO $ getSymbolicLinkStatus destfile)
liftIO $ createDirectoryIfMissing True (parentDir destfile)
liftIO $ if mode == Duplicate || mode == SkipDuplicates
then void $ copyFileExternal srcfile destfile
else moveFile srcfile destfile
Command.Add.perform destfile
+ handleexisting Nothing = noop
+ handleexisting (Just s)
+ | isDirectory s = notoverwriting "(is a directory)"
+ | otherwise = ifM (Annex.getState Annex.force) $
+ ( liftIO $ nukeFile destfile
+ , notoverwriting "(use --force to override)"
+ )
+ notoverwriting why = error $ "not overwriting existing " ++ destfile ++ " " ++ why
pickaction isdup = case mode of
DeDuplicate
| isdup -> Just deletedup