diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-01-02 13:48:56 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-01-02 13:49:02 -0400 |
commit | fda16b5c04db57bbd040116fb7696a1dd40228a0 (patch) | |
tree | 723a1ee61edfde4b7bf98fb198800d8053b33cc8 /Command/Unlock.hs | |
parent | 25761748a79bd1ccb0bb74740b1f840df022468b (diff) |
unlock: Don't allow unlocking files that have never been committed to git before
Avoids an intractable problem that prevents the pre-commit hook from
telling if such a file is intended to be an annexed file or not.
Diffstat (limited to 'Command/Unlock.hs')
-rw-r--r-- | Command/Unlock.hs | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/Command/Unlock.hs b/Command/Unlock.hs index bed618104..56c4f1dc0 100644 --- a/Command/Unlock.hs +++ b/Command/Unlock.hs @@ -10,6 +10,7 @@ module Command.Unlock where import Common.Annex import Command import Annex.Content +import Annex.CatFile import Utility.CopyFile cmd :: [Command] @@ -29,10 +30,10 @@ start :: FilePath -> Key -> CommandStart start file key = do showStart "unlock" file ifM (inAnnex key) - ( ifM (checkDiskSpace Nothing key 0) + ( ifM (isJust <$> catKeyFileHEAD file) ( next $ perform file key , do - warning "not enough disk space to copy file" + warning "this has not yet been committed to git; cannot unlock it" next $ next $ return False ) , do @@ -41,19 +42,24 @@ start file key = do ) perform :: FilePath -> Key -> CommandPerform -perform dest key = do - src <- calcRepo $ gitAnnexLocation key - tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key - liftIO $ createDirectoryIfMissing True (parentDir tmpdest) - showAction "copying" - ifM (liftIO $ copyFileExternal CopyAllMetaData src tmpdest) - ( do - liftIO $ do - removeFile dest - moveFile tmpdest dest - thawContent dest - next $ return True - , do - warning "copy failed!" - next $ return False - ) +perform dest key = ifM (checkDiskSpace Nothing key 0) + ( do + src <- calcRepo $ gitAnnexLocation key + tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key + liftIO $ createDirectoryIfMissing True (parentDir tmpdest) + showAction "copying" + ifM (liftIO $ copyFileExternal CopyAllMetaData src tmpdest) + ( do + liftIO $ do + removeFile dest + moveFile tmpdest dest + thawContent dest + next $ return True + , do + warning "copy failed!" + next $ return False + ) + , do + warning "not enough disk space to copy file" + next $ return False + ) |