2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010, 2013 Joey Hess <id@joeyh.name>
|
2010-11-02 23:04:24 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Add where
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-02 23:04:24 +00:00
|
|
|
import Command
|
2015-12-22 17:23:33 +00:00
|
|
|
import Annex.Ingest
|
2011-10-15 20:21:08 +00:00
|
|
|
import Logs.Location
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2012-12-24 17:37:29 +00:00
|
|
|
import Annex.Content.Direct
|
fully support core.symlinks=false in all relevant symlink handling code
Refactored annex link code into nice clean new library.
Audited and dealt with calls to createSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ createSymbolicLink linktarget file
only when core.symlinks=true
Assistant/WebApp/Configurators/Local.hs: createSymbolicLink link link
test if symlinks can be made
Command/Fix.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/FromKey.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/Indirect.hs: liftIO $ createSymbolicLink l f
refuses to run if core.symlinks=false
Init.hs: createSymbolicLink f f2
test if symlinks can be made
Remote/Directory.hs: go [file] = catchBoolIO $ createSymbolicLink file f >> return True
fast key linking; catches failure to make symlink and falls back to copy
Remote/Git.hs: liftIO $ catchBoolIO $ createSymbolicLink loc file >> return True
ditto
Upgrade/V1.hs: liftIO $ createSymbolicLink link f
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to readSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ catchMaybeIO $ readSymbolicLink file
only when core.symlinks=true
Assistant/Threads/Watcher.hs: ifM ((==) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file))
code that fixes real symlinks when inotify sees them
It's ok to not fix psdueo-symlinks.
Assistant/Threads/Watcher.hs: mlink <- liftIO (catchMaybeIO $ readSymbolicLink file)
ditto
Command/Fix.hs: stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
command only works in indirect mode
Upgrade/V1.hs: getsymlink = takeFileName <$> readSymbolicLink file
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to isSymbolicLink.
(Typically used with getSymbolicLinkStatus, but that is just used because
getFileStatus is not as robust; it also works on pseudolinks.)
Remaining calls are all safe, because:
Assistant/Threads/SanityChecker.hs: | isSymbolicLink s -> addsymlink file ms
only handles staging of symlinks that were somehow not staged
(might need to be updated to support pseudolinks, but this is
only a belt-and-suspenders check anyway, and I've never seen the code run)
Command/Add.hs: if isSymbolicLink s || not (isRegularFile s)
avoids adding symlinks to the annex, so not relevant
Command/Indirect.hs: | isSymbolicLink s -> void $ flip whenAnnexed f $
only allowed on systems that support symlinks
Command/Indirect.hs: whenM (liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f) $ do
ditto
Seek.hs:notSymlink f = liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f
used to find unlocked files, only relevant in indirect mode
Utility/FSEvents.hs: | Files.isSymbolicLink s = runhook addSymlinkHook $ Just s
Utility/FSEvents.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: checkfiletype Files.isSymbolicLink addSymlinkHook f
Utility/Kqueue.hs: | Files.isSymbolicLink s = callhook addSymlinkHook (Just s) change
all above are lower-level, not relevant
Audited and dealt with calls to isSymLink.
Remaining calls are all safe, because:
Annex/Direct.hs: | isSymLink (getmode item) =
This is looking at git diff-tree objects, not files on disk
Command/Unused.hs: | isSymLink (LsTree.mode l) = do
This is looking at git ls-tree, not file on disk
Utility/FileMode.hs:isSymLink :: FileMode -> Bool
Utility/FileMode.hs:isSymLink = checkMode symbolicLinkMode
low-level
Done!!
2013-02-17 19:05:55 +00:00
|
|
|
import Annex.Link
|
|
|
|
import qualified Annex
|
|
|
|
import qualified Annex.Queue
|
2012-12-24 17:37:29 +00:00
|
|
|
import Config
|
2013-02-14 20:54:36 +00:00
|
|
|
import Utility.InodeCache
|
2013-03-29 20:17:13 +00:00
|
|
|
import Annex.FileMatcher
|
2015-12-15 18:02:53 +00:00
|
|
|
import Annex.Version
|
2015-12-16 18:53:41 +00:00
|
|
|
import qualified Database.Keys
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-11-05 22:24:15 +00:00
|
|
|
cmd = notBareRepo $ withGlobalOptions (jobsOption : fileMatchingOptions) $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "add" SectionCommon "add files to annex"
|
2015-07-10 17:18:46 +00:00
|
|
|
paramPaths (seek <$$> optParser)
|
2015-02-06 21:08:14 +00:00
|
|
|
|
2015-07-10 17:18:46 +00:00
|
|
|
data AddOptions = AddOptions
|
|
|
|
{ addThese :: CmdParams
|
|
|
|
, includeDotFiles :: Bool
|
|
|
|
}
|
2014-03-26 18:52:07 +00:00
|
|
|
|
2015-07-10 17:18:46 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser AddOptions
|
|
|
|
optParser desc = AddOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> switch
|
|
|
|
( long "include-dotfiles"
|
|
|
|
<> help "don't skip dotfiles"
|
|
|
|
)
|
2010-12-30 18:19:16 +00:00
|
|
|
|
2013-02-20 18:12:55 +00:00
|
|
|
{- Add acts on both files not checked into git yet, and unlocked files.
|
|
|
|
-
|
|
|
|
- In direct mode, it acts on any files that have changed. -}
|
2015-07-10 17:18:46 +00:00
|
|
|
seek :: AddOptions -> CommandSeek
|
2015-11-05 22:24:15 +00:00
|
|
|
seek o = allowConcurrentOutput $ do
|
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
|
|
|
matcher <- largeFilesMatcher
|
2015-07-10 17:18:46 +00:00
|
|
|
let go a = flip a (addThese o) $ \file -> ifM (checkFileMatcher matcher file <||> Annex.getState Annex.force)
|
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
|
|
|
( start file
|
2015-04-08 20:14:23 +00:00
|
|
|
, startSmall file
|
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
|
|
|
)
|
2015-07-10 17:18:46 +00:00
|
|
|
go $ withFilesNotInGit (not $ includeDotFiles o)
|
2015-12-15 18:17:00 +00:00
|
|
|
ifM (versionSupportsUnlockedPointers <||> isDirect)
|
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
|
|
|
( go withFilesMaybeModified
|
2015-12-15 18:17:00 +00:00
|
|
|
, go withFilesOldUnlocked
|
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
|
|
|
)
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2015-04-08 20:14:23 +00:00
|
|
|
{- Pass file off to git-add. -}
|
|
|
|
startSmall :: FilePath -> CommandStart
|
|
|
|
startSmall file = do
|
|
|
|
showStart "add" file
|
2015-12-02 19:12:33 +00:00
|
|
|
next $ next $ addSmall file
|
2015-12-02 18:48:42 +00:00
|
|
|
|
2015-12-02 19:12:33 +00:00
|
|
|
addSmall :: FilePath -> Annex Bool
|
|
|
|
addSmall file = do
|
2015-04-08 20:16:42 +00:00
|
|
|
showNote "non-large file; adding content to git repository"
|
2015-12-02 19:12:33 +00:00
|
|
|
addFile file
|
2015-07-07 20:15:30 +00:00
|
|
|
|
2015-12-02 19:12:33 +00:00
|
|
|
addFile :: FilePath -> Annex Bool
|
|
|
|
addFile file = do
|
2015-07-08 19:08:02 +00:00
|
|
|
ps <- forceParams
|
|
|
|
Annex.Queue.addCommand "add" (ps++[Param "--"]) [file]
|
2015-12-02 19:12:33 +00:00
|
|
|
return True
|
2015-04-08 20:14:23 +00:00
|
|
|
|
2012-02-14 03:42:44 +00:00
|
|
|
start :: FilePath -> CommandStart
|
2013-02-20 17:37:46 +00:00
|
|
|
start file = ifAnnexed file addpresent add
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
add = do
|
2013-04-23 21:22:56 +00:00
|
|
|
ms <- liftIO $ catchMaybeIO $ getSymbolicLinkStatus file
|
|
|
|
case ms of
|
|
|
|
Nothing -> stop
|
2015-07-07 20:15:30 +00:00
|
|
|
Just s
|
|
|
|
| not (isRegularFile s) && not (isSymbolicLink s) -> stop
|
2013-04-23 21:22:56 +00:00
|
|
|
| otherwise -> do
|
|
|
|
showStart "add" file
|
2015-07-07 20:15:30 +00:00
|
|
|
next $ if isSymbolicLink s
|
2015-12-02 19:12:33 +00:00
|
|
|
then next $ addFile file
|
2015-07-07 20:15:30 +00:00
|
|
|
else perform file
|
2015-12-16 18:53:41 +00:00
|
|
|
addpresent key = ifM versionSupportsUnlockedPointers
|
2014-09-18 18:24:38 +00:00
|
|
|
( do
|
|
|
|
ms <- liftIO $ catchMaybeIO $ getSymbolicLinkStatus file
|
|
|
|
case ms of
|
|
|
|
Just s | isSymbolicLink s -> fixup key
|
2015-12-16 18:53:41 +00:00
|
|
|
_ -> ifM (sameInodeCache file =<< Database.Keys.getInodeCaches key)
|
|
|
|
( stop, add )
|
|
|
|
, ifM isDirect
|
|
|
|
( do
|
|
|
|
ms <- liftIO $ catchMaybeIO $ getSymbolicLinkStatus file
|
|
|
|
case ms of
|
|
|
|
Just s | isSymbolicLink s -> fixup key
|
|
|
|
_ -> ifM (goodContent key file)
|
|
|
|
( stop , add )
|
|
|
|
, fixup key
|
|
|
|
)
|
2013-02-20 17:37:46 +00:00
|
|
|
)
|
|
|
|
fixup key = do
|
2014-09-18 18:24:38 +00:00
|
|
|
-- the annexed symlink is present but not yet added to git
|
2012-11-12 05:05:04 +00:00
|
|
|
showStart "add" file
|
|
|
|
liftIO $ removeFile file
|
2014-09-18 18:24:38 +00:00
|
|
|
whenM isDirect $
|
|
|
|
void $ addAssociatedFile key file
|
2013-09-25 20:07:11 +00:00
|
|
|
next $ next $ cleanup file key Nothing =<< inAnnex key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2012-06-06 17:07:30 +00:00
|
|
|
perform :: FilePath -> CommandPerform
|
2015-12-22 19:23:27 +00:00
|
|
|
perform file = do
|
|
|
|
lockingfile <- not <$> isDirect
|
|
|
|
lockDown lockingfile file >>= ingest >>= go
|
2013-09-25 20:07:11 +00:00
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
go (Just key, cache) = next $ cleanup file key cache True
|
2013-09-25 20:07:11 +00:00
|
|
|
go (Nothing, _) = stop
|
2012-06-06 00:28:34 +00:00
|
|
|
|
2013-09-25 20:07:11 +00:00
|
|
|
cleanup :: FilePath -> Key -> Maybe InodeCache -> Bool -> CommandCleanup
|
|
|
|
cleanup file key mcache hascontent = do
|
2013-02-05 17:41:48 +00:00
|
|
|
ifM (isDirect <&&> pure hascontent)
|
2013-04-04 19:46:33 +00:00
|
|
|
( do
|
2015-01-27 21:38:06 +00:00
|
|
|
l <- calcRepo $ gitAnnexLink file key
|
2013-04-04 19:46:33 +00:00
|
|
|
stageSymlink file =<< hashSymlink l
|
2013-09-25 20:07:11 +00:00
|
|
|
, addLink file key mcache
|
2013-02-05 17:41:48 +00:00
|
|
|
)
|
2014-01-05 18:09:57 +00:00
|
|
|
when hascontent $
|
|
|
|
logStatus key InfoPresent
|
2013-02-05 17:41:48 +00:00
|
|
|
return True
|