From 1d1cb16fe01dd253ee924acc1b6d80262428ea34 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 13 Jan 2016 15:09:47 -0400 Subject: [PATCH] addurl: Refuse to overwrite any existing, non-annexed file. --- Command/AddUrl.hs | 8 ++++++++ debian/changelog | 1 + ...causes_file_redownload_even_if_it_already_present.mdwn | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 516d50a755..838b8fd4d3 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 diff --git a/debian/changelog b/debian/changelog index 68544bcfc2..f5a50db1c4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -35,6 +35,7 @@ git-annex (6.20151219) UNRELEASED; urgency=medium modified the same as typechanged files. * addurl: Added --batch and --with-files options. * addurl: Support --json, particularly useful in --batch mode. + * addurl: Refuse to overwrite any existing, non-annexed file. * Debian: Adjust build dependencies for webapp, DAV. Now available on mips, mipsel, but temporarily removed armel since build is failing there. diff --git a/doc/bugs/addurl_--file__causes_file_redownload_even_if_it_already_present.mdwn b/doc/bugs/addurl_--file__causes_file_redownload_even_if_it_already_present.mdwn index c72084d62a..c3645b6fa6 100644 --- a/doc/bugs/addurl_--file__causes_file_redownload_even_if_it_already_present.mdwn +++ b/doc/bugs/addurl_--file__causes_file_redownload_even_if_it_already_present.mdwn @@ -25,3 +25,8 @@ git-annex version: 6.20160104+gitg0cf96be-1~ndall+1 """] [[!meta author=yoh]] + +> I don't think that the re-download is the bug. The actual problem +> is that the file is present and not an annexed file, so git-annex addurl +> should avoid overwriting it, whatever its content. [[fixed|done]] +> --[[Joey]]