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.
This commit is contained in:
parent
c668ed35be
commit
9f68bb546c
2 changed files with 11 additions and 5 deletions
|
@ -88,16 +88,20 @@ start mode (srcfile, destfile) =
|
||||||
liftIO $ removeFile srcfile
|
liftIO $ removeFile srcfile
|
||||||
next $ return True
|
next $ return True
|
||||||
importfile = do
|
importfile = do
|
||||||
whenM (liftIO $ doesFileExist destfile) $
|
handleexisting =<< liftIO (catchMaybeIO $ getSymbolicLinkStatus destfile)
|
||||||
unlessM (Annex.getState Annex.force) $
|
|
||||||
error $ "not overwriting existing " ++ destfile ++
|
|
||||||
" (use --force to override)"
|
|
||||||
|
|
||||||
liftIO $ createDirectoryIfMissing True (parentDir destfile)
|
liftIO $ createDirectoryIfMissing True (parentDir destfile)
|
||||||
liftIO $ if mode == Duplicate || mode == SkipDuplicates
|
liftIO $ if mode == Duplicate || mode == SkipDuplicates
|
||||||
then void $ copyFileExternal srcfile destfile
|
then void $ copyFileExternal srcfile destfile
|
||||||
else moveFile srcfile destfile
|
else moveFile srcfile destfile
|
||||||
Command.Add.perform 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
|
pickaction isdup = case mode of
|
||||||
DeDuplicate
|
DeDuplicate
|
||||||
| isdup -> Just deletedup
|
| isdup -> Just deletedup
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -17,6 +17,8 @@ git-annex (5.20131131) UNRELEASED; urgency=low
|
||||||
* import: Add --skip-duplicates option.
|
* import: Add --skip-duplicates option.
|
||||||
* Windows: watch and assistant work! (very experimental)
|
* Windows: watch and assistant work! (very experimental)
|
||||||
* lock: Require --force. Closes: #731606
|
* lock: Require --force. Closes: #731606
|
||||||
|
* import: better handling of overwriting an existing file/directory/broken
|
||||||
|
link when importing
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Sun, 01 Dec 2013 13:57:58 -0400
|
-- Joey Hess <joeyh@debian.org> Sun, 01 Dec 2013 13:57:58 -0400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue