From eab4110a9010f1654724e712b8fe2d675132a7ef Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 5 Nov 2015 18:45:52 -0400 Subject: import: Avoid very ugly error messages when the directory files are imported to is not a directort, but perhaps an annexed file. --- Command/Import.hs | 16 ++++++++++++++-- debian/changelog | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Command/Import.hs b/Command/Import.hs index 3ace2d2b0..0dbf2e44a 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -89,7 +89,7 @@ start mode (srcfile, destfile) = warning "Could not verify that the content is still present in the annex; not removing from the import location." stop ) - importfile = do + importfile = checkdestdir $ do ignored <- not <$> Annex.getState Annex.force <&&> checkIgnored destfile if ignored then do @@ -99,14 +99,26 @@ start mode (srcfile, destfile) = existing <- liftIO (catchMaybeIO $ getSymbolicLinkStatus destfile) case existing of Nothing -> importfilechecked - (Just s) + Just s | isDirectory s -> notoverwriting "(is a directory)" + | isSymbolicLink s -> notoverwriting "(is a symlink)" | otherwise -> ifM (Annex.getState Annex.force) ( do liftIO $ nukeFile destfile importfilechecked , notoverwriting "(use --force to override, or a duplication option such as --deduplicate to clean up)" ) + checkdestdir cont = do + let destdir = parentDir destfile + existing <- liftIO (catchMaybeIO $ getSymbolicLinkStatus destdir) + case existing of + Nothing -> cont + Just s + | isDirectory s -> cont + | otherwise -> do + warning $ "not importing " ++ destfile ++ " because " ++ destdir ++ " is not a directory" + stop + importfilechecked = do liftIO $ createDirectoryIfMissing True (parentDir destfile) liftIO $ if mode == Duplicate || mode == SkipDuplicates diff --git a/debian/changelog b/debian/changelog index da322b50e..c0d4c510d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,8 @@ git-annex (5.20151102.2) UNRELEASED; urgency=medium This allows nicely displayed messages when using the -J flag. * Additional commands now suppport the -J flag: fsck, drop, add, addurl, import + * import: Avoid very ugly error messages when the directory files + are imported to is not a directort, but perhaps an annexed file. -- Joey Hess Wed, 04 Nov 2015 12:50:20 -0400 -- cgit v1.2.3