summaryrefslogtreecommitdiff
path: root/Annex/Ingest.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-05 17:22:19 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-05 17:22:19 -0400
commit903241502a6ad1a4845ac2d131ef7fc2b547400d (patch)
treefba85c9751a19aa0873e0f2bd837a1b000588508 /Annex/Ingest.hs
parentcf911557bf4bb27768c4fc5ac482e8f827807497 (diff)
use TopFilePath for associated files
Fixes several bugs with updates of pointer files. When eg, running git annex drop --from localremote it was updating the pointer file in the local repository, not the remote. Also, fixes drop ../foo when run in a subdir, and probably lots of other problems. Test suite drops from ~30 to 11 failures now. TopFilePath is used to force thinking about what the filepath is relative to. The data stored in the sqlite db is still just a plain string, and TopFilePath is a newtype, so there's no overhead involved in using it in DataBase.Keys.
Diffstat (limited to 'Annex/Ingest.hs')
-rw-r--r--Annex/Ingest.hs26
1 files changed, 15 insertions, 11 deletions
diff --git a/Annex/Ingest.hs b/Annex/Ingest.hs
index 3ab7566c8..73f8a39ca 100644
--- a/Annex/Ingest.hs
+++ b/Annex/Ingest.hs
@@ -37,6 +37,7 @@ import Utility.InodeCache
import Annex.ReplaceFile
import Utility.Tmp
import Utility.CopyFile
+import Git.FilePath
import Annex.InodeSentinal
#ifdef WITH_CLIBS
#ifndef __ANDROID__
@@ -186,15 +187,18 @@ finishIngestUnlocked key source = do
finishIngestUnlocked' :: Key -> KeySource -> Annex ()
finishIngestUnlocked' key source = do
- Database.Keys.addAssociatedFile key (keyFilename source)
+ Database.Keys.addAssociatedFile key =<< inRepo (toTopFilePath (keyFilename source))
populateAssociatedFiles key source
{- Copy to any other locations using the same key. -}
populateAssociatedFiles :: Key -> KeySource -> Annex ()
populateAssociatedFiles key source = do
- otherfs <- filter (/= keyFilename source) <$> Database.Keys.getAssociatedFiles key
obj <- calcRepo (gitAnnexLocation key)
- forM_ otherfs $
+ g <- Annex.gitRepo
+ ingestedf <- flip fromTopFilePath g
+ <$> inRepo (toTopFilePath (keyFilename source))
+ afs <- map (`fromTopFilePath` g) <$> Database.Keys.getAssociatedFiles key
+ forM_ (filter (/= ingestedf) afs) $
populatePointerFile key obj
cleanCruft :: KeySource -> Annex ()
@@ -206,16 +210,18 @@ cleanCruft source = when (contentLocation source /= keyFilename source) $
-- content. Clean up from that.
cleanOldKeys :: FilePath -> Key -> Annex ()
cleanOldKeys file newkey = do
+ g <- Annex.gitRepo
+ ingestedf <- flip fromTopFilePath g <$> inRepo (toTopFilePath file)
+ topf <- inRepo (toTopFilePath file)
oldkeys <- filter (/= newkey)
- <$> Database.Keys.getAssociatedKey file
- mapM_ go oldkeys
- where
- go key = do
+ <$> Database.Keys.getAssociatedKey topf
+ forM_ oldkeys $ \key -> do
obj <- calcRepo (gitAnnexLocation key)
caches <- Database.Keys.getInodeCaches key
unlessM (sameInodeCache obj caches) $ do
unlinkAnnex key
- fs <- filter (/= file)
+ fs <- filter (/= ingestedf)
+ . map (`fromTopFilePath` g)
<$> Database.Keys.getAssociatedFiles key
fs' <- filterM (`sameInodeCache` caches) fs
case fs' of
@@ -225,9 +231,7 @@ cleanOldKeys file newkey = do
(f:_) -> do
ic <- withTSDelta (liftIO . genInodeCache f)
void $ linkToAnnex key f ic
- _ -> lostcontent
- where
- lostcontent = logStatus key InfoMissing
+ _ -> logStatus key InfoMissing
{- On error, put the file back so it doesn't seem to have vanished.
- This can be called before or after the symlink is in place. -}