summaryrefslogtreecommitdiff
path: root/Command/Unlock.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-09 15:59:49 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-09 15:59:49 -0400
commit536bc97d25479ac969273b49442c2fd8c31358c4 (patch)
treeaeb19878fd34ff88e69f0f1c3faa019e8cc180c5 /Command/Unlock.hs
parentd56feda25dd82ffa34fe5e3f28eff3ecf9eac5b5 (diff)
lock and unlock subcommands
Diffstat (limited to 'Command/Unlock.hs')
-rw-r--r--Command/Unlock.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Command/Unlock.hs b/Command/Unlock.hs
new file mode 100644
index 000000000..57d4ad87a
--- /dev/null
+++ b/Command/Unlock.hs
@@ -0,0 +1,36 @@
+{- git-annex command
+ -
+ - Copyright 2010 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.Unlock where
+
+import Control.Monad.State (liftIO)
+import System.Directory
+
+import Command
+import qualified Annex
+import Types
+import Messages
+import Locations
+import Utility
+
+{- The unlock subcommand replaces the symlink with a copy of the file's
+ - content. -}
+start :: SubCmdStartString
+start file = isAnnexed file $ \(key, _) -> do
+ showStart "unlock" file
+ return $ Just $ perform file key
+
+perform :: FilePath -> Key -> SubCmdPerform
+perform dest key = do
+ g <- Annex.gitRepo
+ let src = annexLocation g key
+ liftIO $ removeFile dest
+ showNote "copying..."
+ ok <- liftIO $ boolSystem "cp" ["-p", src, dest]
+ if ok
+ then return $ Just $ return True -- no cleanup needed
+ else error "cp failed!"