2010-11-09 15:59:49 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Unlock where
|
|
|
|
|
2011-10-05 16:02:51 -04:00
|
|
|
import Common.Annex
|
2010-11-09 15:59:49 -04:00
|
|
|
import Command
|
2011-10-04 00:40:47 -04:00
|
|
|
import Annex.Content
|
2011-07-05 20:24:10 -04:00
|
|
|
import Utility.CopyFile
|
2010-11-09 15:59:49 -04:00
|
|
|
|
2011-10-29 15:19:05 -04:00
|
|
|
def :: [Command]
|
|
|
|
def =
|
2011-10-27 16:31:35 -04:00
|
|
|
[ c "unlock" "unlock files for modification"
|
|
|
|
, c "edit" "same as unlock"
|
2010-12-30 15:06:26 -04:00
|
|
|
]
|
2011-10-27 16:31:35 -04:00
|
|
|
where
|
2011-10-29 15:19:05 -04:00
|
|
|
c n = command n paramPaths seek
|
2010-12-30 15:06:26 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
seek :: [CommandSeek]
|
2011-11-10 23:35:08 -04:00
|
|
|
seek = [withFilesInGit $ whenAnnexed start]
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2010-11-09 15:59:49 -04:00
|
|
|
{- The unlock subcommand replaces the symlink with a copy of the file's
|
|
|
|
- content. -}
|
2011-12-31 04:11:39 -04:00
|
|
|
start :: FilePath -> (Key, Backend) -> CommandStart
|
2011-11-10 23:35:08 -04:00
|
|
|
start file (key, _) = do
|
2011-01-14 00:02:33 -04:00
|
|
|
showStart "unlock" file
|
2011-05-15 02:02:46 -04:00
|
|
|
next $ perform file key
|
2010-11-09 15:59:49 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
2010-11-09 15:59:49 -04:00
|
|
|
perform dest key = do
|
2011-07-05 18:31:46 -04:00
|
|
|
unlessM (inAnnex key) $ error "content not present"
|
2012-04-20 14:57:57 -04:00
|
|
|
unlessM (checkDiskSpace Nothing key 0) $ error "cannot unlock"
|
2011-01-14 00:02:33 -04:00
|
|
|
|
2011-11-28 22:43:51 -04:00
|
|
|
src <- inRepo $ gitAnnexLocation key
|
2011-11-08 15:34:10 -04:00
|
|
|
tmpdest <- fromRepo $ gitAnnexTmpLocation key
|
2011-06-20 22:38:18 -04:00
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
|
2011-07-19 14:07:23 -04:00
|
|
|
showAction "copying"
|
2011-10-03 22:24:57 -04:00
|
|
|
ok <- liftIO $ copyFileExternal src tmpdest
|
2010-11-09 15:59:49 -04:00
|
|
|
if ok
|
2010-11-10 12:50:00 -04:00
|
|
|
then do
|
2011-06-20 22:38:18 -04:00
|
|
|
liftIO $ do
|
|
|
|
removeFile dest
|
support .git/annex on a different disk than the rest of the repo
The only fully supported thing is to have the main repository on one disk,
and .git/annex on another. Only commands that move data in/out of the annex
will need to copy it across devices.
There is only partial support for putting arbitrary subdirectories of
.git/annex on different devices. For one thing, but this can require more
copies to be done. For example, when .git/annex/tmp is on one device, and
.git/annex/journal on another, every journal write involves a call to
mv(1). Also, there are a few places that make hard links between various
subdirectories of .git/annex with createLink, that are not handled.
In the common case without cross-device, the new moveFile is actually
faster than renameFile, avoiding an unncessary stat to check that a file
(not a directory) is being moved. Of course if a cross-device move is
needed, it is as slow as mv(1) of the data.
2011-11-28 15:26:27 -04:00
|
|
|
moveFile tmpdest dest
|
2012-04-21 14:06:36 -04:00
|
|
|
thawContent dest
|
2011-05-15 02:02:46 -04:00
|
|
|
next $ return True
|
2010-11-18 13:48:28 -04:00
|
|
|
else error "copy failed!"
|