fix sameInodeCache to check the inode change sentinal

This should fix the problem where the assistant, on Android, re-adds every
file on startup.
This commit is contained in:
Joey Hess 2013-02-22 15:19:28 -04:00
parent d868a785a2
commit 4689fbde35

View file

@ -103,7 +103,10 @@ changedFileStatus :: Key -> FileStatus -> Annex Bool
changedFileStatus key status = do changedFileStatus key status = do
old <- recordedInodeCache key old <- recordedInodeCache key
let curr = toInodeCache status let curr = toInodeCache status
return $ curr /= old case (old, curr) of
(Just o, Just c) -> compareInodeCaches o c
(Nothing, Nothing) -> return True
_ -> return False
{- Gets the recorded inode cache for a key. -} {- Gets the recorded inode cache for a key. -}
recordedInodeCache :: Key -> Annex (Maybe InodeCache) recordedInodeCache :: Key -> Annex (Maybe InodeCache)
@ -130,21 +133,22 @@ removeInodeCache key = withInodeCacheFile key $ \f -> do
withInodeCacheFile :: Key -> (FilePath -> Annex a) -> Annex a withInodeCacheFile :: Key -> (FilePath -> Annex a) -> Annex a
withInodeCacheFile key a = a =<< inRepo (gitAnnexInodeCache key) withInodeCacheFile key a = a =<< inRepo (gitAnnexInodeCache key)
{- Checks if a file's InodeCache matches its current info. {- Checks if a InodeCache matches the current version of a file. -}
-
- If the inodes have changed, only the size and mtime are compared.
-}
sameInodeCache :: FilePath -> Maybe InodeCache -> Annex Bool sameInodeCache :: FilePath -> Maybe InodeCache -> Annex Bool
sameInodeCache _ Nothing = return False sameInodeCache _ Nothing = return False
sameInodeCache file (Just old) = go =<< liftIO (genInodeCache file) sameInodeCache file (Just old) = go =<< liftIO (genInodeCache file)
where where
go Nothing = return False go Nothing = return False
go (Just curr) go (Just curr) = compareInodeCaches curr old
| curr == old = return True
| otherwise = ifM inodesChanged {- If the inodes have changed, only the size and mtime are compared. -}
( return $ compareWeak curr old compareInodeCaches :: InodeCache -> InodeCache -> Annex Bool
, return False compareInodeCaches x y
) | x == y = return True
| otherwise = ifM inodesChanged
( return $ compareWeak x y
, return False
)
{- Some filesystems get new inodes each time they are mounted. {- Some filesystems get new inodes each time they are mounted.
- In order to work on such a filesystem, a sentinal file is used to detect - In order to work on such a filesystem, a sentinal file is used to detect