2010-11-09 19:59:49 +00: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 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-09 19:59:49 +00:00
|
|
|
import Command
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2011-07-06 00:24:10 +00:00
|
|
|
import Utility.CopyFile
|
2010-11-09 19:59:49 +00:00
|
|
|
|
2014-10-14 18:20:10 +00:00
|
|
|
cmd :: [Command]
|
|
|
|
cmd =
|
2011-10-27 20:31:35 +00:00
|
|
|
[ c "unlock" "unlock files for modification"
|
|
|
|
, c "edit" "same as unlock"
|
2010-12-30 19:06:26 +00:00
|
|
|
]
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2013-03-24 22:28:21 +00:00
|
|
|
c n = notDirect . command n paramPaths seek SectionCommon
|
2010-12-30 19:06:26 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seek :: CommandSeek
|
|
|
|
seek = withFilesInGit $ whenAnnexed start
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2010-11-09 19:59:49 +00:00
|
|
|
{- The unlock subcommand replaces the symlink with a copy of the file's
|
|
|
|
- content. -}
|
2014-04-17 22:03:39 +00:00
|
|
|
start :: FilePath -> Key -> CommandStart
|
2014-08-10 19:16:24 +00:00
|
|
|
start file key = do
|
2011-01-14 04:02:33 +00:00
|
|
|
showStart "unlock" file
|
2014-08-10 19:16:24 +00:00
|
|
|
ifM (inAnnex key)
|
|
|
|
( ifM (checkDiskSpace Nothing key 0)
|
|
|
|
( next $ perform file key
|
|
|
|
, do
|
|
|
|
warning "not enough disk space to copy file"
|
|
|
|
next $ next $ return False
|
|
|
|
)
|
2014-08-09 15:09:54 +00:00
|
|
|
, do
|
2014-08-10 19:16:24 +00:00
|
|
|
warning "content not present; cannot unlock"
|
2014-08-09 15:09:54 +00:00
|
|
|
next $ next $ return False
|
|
|
|
)
|
2010-11-09 19:59:49 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
2010-11-09 19:59:49 +00:00
|
|
|
perform dest key = do
|
2013-04-04 19:46:33 +00:00
|
|
|
src <- calcRepo $ gitAnnexLocation key
|
2014-02-26 20:52:56 +00:00
|
|
|
tmpdest <- fromRepo $ gitAnnexTmpObjectLocation key
|
2011-06-21 02:38:18 +00:00
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir tmpdest)
|
2011-07-19 18:07:23 +00:00
|
|
|
showAction "copying"
|
2014-08-27 00:06:43 +00:00
|
|
|
ifM (liftIO $ copyFileExternal CopyAllMetaData src tmpdest)
|
2012-12-13 04:45:27 +00:00
|
|
|
( do
|
2011-06-21 02:38:18 +00: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 19:26:27 +00:00
|
|
|
moveFile tmpdest dest
|
2012-04-21 18:06:36 +00:00
|
|
|
thawContent dest
|
2011-05-15 06:02:46 +00:00
|
|
|
next $ return True
|
2014-08-09 15:09:54 +00:00
|
|
|
, do
|
|
|
|
warning "copy failed!"
|
|
|
|
next $ return False
|
2012-12-13 04:45:27 +00:00
|
|
|
)
|