import: Avoid very ugly error messages when the directory files are imported to is...
authorJoey Hess <joeyh@joeyh.name>
Thu, 5 Nov 2015 22:45:52 +0000 (18:45 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 5 Nov 2015 22:46:05 +0000 (18:46 -0400)
Command/Import.hs
debian/changelog

index 3ace2d2b0592d070b7fef7f477eddd1eef728b3e..0dbf2e44a541509e081eae76c6b65a3d82510c56 100644 (file)
@@ -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
index da322b50eaba56875ec9b7ce44be06045b5bd0b4..c0d4c510d5e1242ba9bae7314c0e3e5e1e882cf3 100644 (file)
@@ -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 <id@joeyh.name>  Wed, 04 Nov 2015 12:50:20 -0400