2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Add where
|
|
|
|
|
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
import System.Posix.Files
|
|
|
|
|
|
|
|
import Command
|
2011-04-07 17:59:31 +00:00
|
|
|
import qualified AnnexQueue
|
2010-11-02 23:04:24 +00:00
|
|
|
import qualified Backend
|
|
|
|
import LocationLog
|
|
|
|
import Types
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2011-02-28 20:10:16 +00:00
|
|
|
import Utility
|
2011-03-15 03:00:23 +00:00
|
|
|
import Touch
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
2011-03-19 22:58:49 +00:00
|
|
|
command = [repoCommand "add" paramPath seek "add files to annex"]
|
2010-12-30 18:19:16 +00:00
|
|
|
|
2010-11-11 22:54:52 +00:00
|
|
|
{- Add acts on both files not checked into git yet, and unlocked files. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-11 22:54:52 +00:00
|
|
|
seek = [withFilesNotInGit start, withFilesUnlocked start]
|
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- The add subcommand annexes a file, storing it in a backend, and then
|
|
|
|
- moving it into the annex directory and setting up the symlink pointing
|
|
|
|
- to its content. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartBackendFile
|
2010-11-02 23:04:24 +00:00
|
|
|
start pair@(file, _) = notAnnexed file $ do
|
|
|
|
s <- liftIO $ getSymbolicLinkStatus file
|
2010-11-22 21:51:55 +00:00
|
|
|
if (isSymbolicLink s) || (not $ isRegularFile s)
|
2010-11-02 23:04:24 +00:00
|
|
|
then return Nothing
|
|
|
|
else do
|
|
|
|
showStart "add" file
|
|
|
|
return $ Just $ perform pair
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
perform :: BackendFile -> CommandPerform
|
2010-11-02 23:04:24 +00:00
|
|
|
perform (file, backend) = do
|
|
|
|
stored <- Backend.storeFileKey file backend
|
2010-11-22 21:51:55 +00:00
|
|
|
case stored of
|
2010-11-02 23:04:24 +00:00
|
|
|
Nothing -> return Nothing
|
2011-01-08 19:54:14 +00:00
|
|
|
Just (key, _) -> do
|
|
|
|
moveAnnex key file
|
|
|
|
return $ Just $ cleanup file key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: FilePath -> Key -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup file key = do
|
|
|
|
logStatus key ValuePresent
|
2010-11-08 23:26:37 +00:00
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
link <- calcGitLink file key
|
|
|
|
liftIO $ createSymbolicLink link file
|
2011-03-15 03:00:23 +00:00
|
|
|
|
|
|
|
-- touch the symlink to have the same mtime as the file it points to
|
|
|
|
s <- liftIO $ getFileStatus file
|
|
|
|
let mtime = modificationTime s
|
2011-03-20 18:04:39 +00:00
|
|
|
liftIO $ touch file (TimeSpec mtime) False
|
2011-03-15 03:00:23 +00:00
|
|
|
|
2011-04-07 17:59:31 +00:00
|
|
|
AnnexQueue.add "add" [Param "--"] file
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|