v6: fix locking modified file when the content is not present
authorJoey Hess <joeyh@joeyh.name>
Wed, 16 Dec 2015 19:35:42 +0000 (15:35 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 16 Dec 2015 19:35:42 +0000 (15:35 -0400)
Command/Lock.hs

index 16ddce94248f0e5b8d5eb6c5de0132c452fc208c..741c18c150fd0ada8a2490ef40a335620a43e3ea 100644 (file)
@@ -65,15 +65,16 @@ performNew file key filemodified = do
        next $ cleanupNew file key
   where
        lockdown obj = do
-               ifM (sameInodeCache obj =<< Database.Keys.getInodeCaches key)
+               ifM (catchBoolIO $ sameInodeCache obj =<< Database.Keys.getInodeCaches key)
                        ( breakhardlink obj
                        , repopulate obj
                        )
-               freezeContent obj
+               whenM (liftIO $ doesFileExist obj) $
+                       freezeContent obj
 
        -- It's ok if the file is hard linked to obj, but if some other
        -- associated file is, we need to break that link to lock down obj.
-       breakhardlink obj = whenM ((> 1) . linkCount <$> liftIO (getFileStatus obj)) $ do
+       breakhardlink obj = whenM (catchBoolIO $ (> 1) . linkCount <$> liftIO (getFileStatus obj)) $ do
                mfc <- withTSDelta (liftIO . genInodeCache file)
                unlessM (sameInodeCache obj (maybeToList mfc)) $ do
                        modifyContent obj $ replaceFile obj $ \tmp -> do