2def1d0a23
In c6632ee5c8
, it actually only handled
uploading objects to a shared repository. To avoid verification when
downloading objects from a shared repository, was a lot harder.
On the plus side, if the process of downloading a file from a remote
is able to verify its content on the side, the remote can indicate this
now, and avoid the extra post-download verification.
As of yet, I don't have any remotes (except Git) using this ability.
Some more work would be needed to support it in special remotes.
It would make sense for tahoe to implicitly verify things downloaded from it;
as long as you trust your tahoe server (which typically runs locally),
there's cryptographic integrity. OTOH, despite bup being based on shas,
a bup repo under an attacker's control could have the git ref used for an
object changed, and so a bup repo shouldn't implicitly verify. Indeed,
tahoe seems unique in being trustworthy enough to implicitly verify.
75 lines
1.9 KiB
Haskell
75 lines
1.9 KiB
Haskell
{- git-annex command
|
|
-
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
-}
|
|
|
|
module Command.ReKey where
|
|
|
|
import Common.Annex
|
|
import Command
|
|
import qualified Annex
|
|
import Types.Key
|
|
import Annex.Content
|
|
import qualified Command.Add
|
|
import Logs.Web
|
|
import Logs.Location
|
|
import Utility.CopyFile
|
|
import qualified Remote
|
|
|
|
cmd :: Command
|
|
cmd = notDirect $
|
|
command "rekey" SectionPlumbing
|
|
"change keys used for files"
|
|
(paramRepeating $ paramPair paramPath paramKey)
|
|
(withParams seek)
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
seek = withPairs start
|
|
|
|
start :: (FilePath, String) -> CommandStart
|
|
start (file, keyname) = ifAnnexed file go stop
|
|
where
|
|
newkey = fromMaybe (error "bad key") $ file2key keyname
|
|
go oldkey
|
|
| oldkey == newkey = stop
|
|
| otherwise = do
|
|
showStart "rekey" file
|
|
next $ perform file oldkey newkey
|
|
|
|
perform :: FilePath -> Key -> Key -> CommandPerform
|
|
perform file oldkey newkey = do
|
|
present <- inAnnex oldkey
|
|
_ <- if present
|
|
then linkKey oldkey newkey
|
|
else do
|
|
unlessM (Annex.getState Annex.force) $
|
|
error $ file ++ " is not available (use --force to override)"
|
|
return True
|
|
next $ cleanup file oldkey newkey
|
|
|
|
{- Make a hard link to the old key content (when supported),
|
|
- to avoid wasting disk space. -}
|
|
linkKey :: Key -> Key -> Annex Bool
|
|
linkKey oldkey newkey = getViaTmp' DefaultVerify newkey $ \tmp -> unVerified $ do
|
|
src <- calcRepo $ gitAnnexLocation oldkey
|
|
liftIO $ ifM (doesFileExist tmp)
|
|
( return True
|
|
, createLinkOrCopy src tmp
|
|
)
|
|
|
|
cleanup :: FilePath -> Key -> Key -> CommandCleanup
|
|
cleanup file oldkey newkey = do
|
|
-- If the old key had some associated urls, record them for
|
|
-- the new key as well.
|
|
urls <- getUrls oldkey
|
|
forM_ urls $ \url -> do
|
|
r <- Remote.claimingUrl url
|
|
setUrlPresent (Remote.uuid r) newkey url
|
|
|
|
-- Update symlink to use the new key.
|
|
liftIO $ removeFile file
|
|
Command.Add.addLink file newkey Nothing
|
|
logStatus newkey InfoPresent
|
|
return True
|