remove Eq instance for InodeCache

There are two types of equality here, and which one is right varies,
so this forces me to consider and choose between them.

Based on this, I learned that the commit in git anex sync was
always doing a strong comparison, even when in a repository where
the inodes had changed. Fixed that.
This commit is contained in:
Joey Hess 2013-03-11 02:57:48 -04:00
parent eef93fc0a5
commit 40df015d90
4 changed files with 19 additions and 11 deletions

View file

@ -13,6 +13,7 @@ module Annex.Content.Direct (
recordedInodeCache, recordedInodeCache,
updateInodeCache, updateInodeCache,
writeInodeCache, writeInodeCache,
compareInodeCaches,
sameInodeCache, sameInodeCache,
sameFileStatus, sameFileStatus,
removeInodeCache, removeInodeCache,
@ -146,7 +147,7 @@ sameFileStatus key status = do
{- If the inodes have changed, only the size and mtime are compared. -} {- If the inodes have changed, only the size and mtime are compared. -}
compareInodeCaches :: InodeCache -> InodeCache -> Annex Bool compareInodeCaches :: InodeCache -> InodeCache -> Annex Bool
compareInodeCaches x y compareInodeCaches x y
| x == y = return True | x `compareStrong` y = return True
| otherwise = ifM inodesChanged | otherwise = ifM inodesChanged
( return $ compareWeak x y ( return $ compareWeak x y
, return False , return False
@ -167,7 +168,7 @@ inodesChanged = maybe calc return =<< Annex.getState Annex.inodeschanged
=<< fromRepo gitAnnexInodeSentinal =<< fromRepo gitAnnexInodeSentinal
scached <- readInodeSentinalFile scached <- readInodeSentinalFile
let changed = case (scache, scached) of let changed = case (scache, scached) of
(Just c1, Just c2) -> c1 /= c2 (Just c1, Just c2) -> not $ compareStrong c1 c2
_ -> True _ -> True
Annex.changeState $ \s -> s { Annex.inodeschanged = Just changed } Annex.changeState $ \s -> s { Annex.inodeschanged = Just changed }
return changed return changed

View file

@ -51,8 +51,10 @@ stageDirect = do
- modified, so compare the cache to see if - modified, so compare the cache to see if
- it really was. -} - it really was. -}
oldcache <- recordedInodeCache key oldcache <- recordedInodeCache key
when (oldcache /= Just cache) $ case oldcache of
modifiedannexed file key cache Nothing -> modifiedannexed file key cache
Just c -> unlessM (compareInodeCaches c cache) $
modifiedannexed file key cache
(Just key, Nothing, _) -> deletedannexed file key (Just key, Nothing, _) -> deletedannexed file key
(Nothing, Nothing, _) -> deletegit file (Nothing, Nothing, _) -> deletegit file
(_, Just _, _) -> addgit file (_, Just _, _) -> addgit file

View file

@ -109,11 +109,10 @@ ingest (Just source) = do
backend <- chooseBackend $ keyFilename source backend <- chooseBackend $ keyFilename source
k <- genKey source backend k <- genKey source backend
cache <- liftIO $ genInodeCache $ contentLocation source cache <- liftIO $ genInodeCache $ contentLocation source
case inodeCache source of case (cache, inodeCache source) of
Nothing -> go k cache (_, Nothing) -> go k cache
Just c (Just newc, Just c) | compareStrong c newc -> go k cache
| (Just c == cache) -> go k cache _ -> failure
| otherwise -> failure
where where
go k cache = ifM isDirect ( godirect k cache , goindirect k cache ) go k cache = ifM isDirect ( godirect k cache , goindirect k cache )

View file

@ -12,7 +12,11 @@ import System.Posix.Types
import Utility.QuickCheck import Utility.QuickCheck
data InodeCache = InodeCache FileID FileOffset EpochTime data InodeCache = InodeCache FileID FileOffset EpochTime
deriving (Eq, Show) deriving (Show)
compareStrong :: InodeCache -> InodeCache -> Bool
compareStrong (InodeCache inode1 size1 mtime1) (InodeCache inode2 size2 mtime2) =
inode1 == inode2 && size1 == size2 && mtime1 == mtime2
{- Weak comparison of the inode caches, comparing the size and mtime, but {- Weak comparison of the inode caches, comparing the size and mtime, but
- not the actual inode. Useful when inodes have changed, perhaps - not the actual inode. Useful when inodes have changed, perhaps
@ -54,4 +58,6 @@ instance Arbitrary InodeCache where
<*> arbitrary <*> arbitrary
prop_read_show_inodecache :: InodeCache -> Bool prop_read_show_inodecache :: InodeCache -> Bool
prop_read_show_inodecache c = readInodeCache (showInodeCache c) == Just c prop_read_show_inodecache c = case readInodeCache (showInodeCache c) of
Nothing -> False
Just c' -> compareStrong c c'