summaryrefslogtreecommitdiff
path: root/Command/AddUrl.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-13 15:09:47 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-13 15:09:47 -0400
commitc0f5b772f52c5c6d30009fd35b4597f27a3a1a5f (patch)
tree8d7b6011c49b1d0b0baa9559c25370d53caba09f /Command/AddUrl.hs
parent3b72782586f5f6872d00891f6b46f5a8cb654e7a (diff)
addurl: Refuse to overwrite any existing, non-annexed file.
Diffstat (limited to 'Command/AddUrl.hs')
-rw-r--r--Command/AddUrl.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs
index 516d50a75..838b8fd4d 100644
--- a/Command/AddUrl.hs
+++ b/Command/AddUrl.hs
@@ -259,6 +259,7 @@ performQuvi relaxed pageurl videourl file = ifAnnexed file addurl geturl
#ifdef WITH_QUVI
addUrlFileQuvi :: Bool -> URLString -> URLString -> FilePath -> Annex (Maybe Key)
addUrlFileQuvi relaxed quviurl videourl file = do
+ checkDoesNotExist file
let key = Backend.URL.fromUrl quviurl Nothing
ifM (pure relaxed <||> Annex.getState Annex.fast)
( do
@@ -309,12 +310,19 @@ addUrlChecked relaxed url u checkexistssize key
addUrlFile :: Bool -> URLString -> Url.UrlInfo -> FilePath -> Annex (Maybe Key)
addUrlFile relaxed url urlinfo file = do
+ checkDoesNotExist file
liftIO $ createDirectoryIfMissing True (parentDir file)
ifM (Annex.getState Annex.fast <||> pure relaxed)
( nodownload url urlinfo file
, downloadWeb url urlinfo file
)
+checkDoesNotExist :: FilePath -> Annex ()
+checkDoesNotExist file = go =<< liftIO (catchMaybeIO $ getSymbolicLinkStatus file)
+ where
+ go Nothing = return ()
+ go (Just _) = error $ file ++ " already exists and is not annexed; not overwriting"
+
downloadWeb :: URLString -> Url.UrlInfo -> FilePath -> Annex (Maybe Key)
downloadWeb url urlinfo file = do
let dummykey = addSizeUrlKey urlinfo $ Backend.URL.fromUrl url Nothing