2014-01-02 17:12:32 +00:00
|
|
|
{- Adds readonly support to remotes.
|
|
|
|
-
|
2019-05-28 15:04:28 +00:00
|
|
|
- Copyright 2013-2019 Joey Hess <id@joeyh.name>
|
2014-01-02 17:12:32 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-01-02 17:12:32 +00:00
|
|
|
-}
|
|
|
|
|
2015-08-17 15:21:38 +00:00
|
|
|
module Remote.Helper.ReadOnly
|
|
|
|
( adjustReadOnly
|
|
|
|
, readonlyStoreKey
|
|
|
|
, readonlyStorer
|
|
|
|
, readonlyRemoveKey
|
|
|
|
) where
|
2014-01-02 17:12:32 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-01-02 17:12:32 +00:00
|
|
|
import Types.Remote
|
2015-08-17 15:21:38 +00:00
|
|
|
import Types.StoreRetrieve
|
2019-05-28 15:17:25 +00:00
|
|
|
import Types.Import
|
|
|
|
import Types.Export
|
2015-08-17 15:21:38 +00:00
|
|
|
import Utility.Metered
|
2014-01-02 17:12:32 +00:00
|
|
|
|
|
|
|
{- Adds support for read-only remotes, by replacing the
|
|
|
|
- methods that write to a remote with dummies that fail.
|
|
|
|
-
|
|
|
|
- Note that disabling git pushes to remotes is not handled here.
|
|
|
|
-}
|
|
|
|
adjustReadOnly :: Remote -> Remote
|
|
|
|
adjustReadOnly r
|
|
|
|
| remoteAnnexReadOnly (gitconfig r) = r
|
2015-08-17 15:21:38 +00:00
|
|
|
{ storeKey = readonlyStoreKey
|
|
|
|
, removeKey = readonlyRemoveKey
|
2014-01-02 17:12:32 +00:00
|
|
|
, repairRepo = Nothing
|
2019-05-28 15:17:25 +00:00
|
|
|
, exportActions = (exportActions r)
|
2019-05-28 15:04:28 +00:00
|
|
|
{ storeExport = readonlyStoreExport
|
|
|
|
, removeExport = readonlyRemoveExport
|
|
|
|
, removeExportDirectory = Just readonlyRemoveExportDirectory
|
2024-03-09 17:37:51 +00:00
|
|
|
, renameExport = Nothing
|
2019-05-28 15:04:28 +00:00
|
|
|
}
|
2019-05-28 15:17:25 +00:00
|
|
|
, importActions = (importActions r)
|
|
|
|
{ storeExportWithContentIdentifier = readonlyStoreExportWithContentIdentifier
|
2019-05-28 15:04:28 +00:00
|
|
|
, removeExportWithContentIdentifier = readonlyRemoveExportWithContentIdentifier
|
|
|
|
, removeExportDirectoryWhenEmpty = Just readonlyRemoveExportDirectory
|
|
|
|
}
|
2014-01-02 17:12:32 +00:00
|
|
|
}
|
|
|
|
| otherwise = r
|
2015-08-17 15:21:38 +00:00
|
|
|
|
2024-07-01 14:42:27 +00:00
|
|
|
readonlyStoreKey :: Key -> AssociatedFile -> Maybe FilePath -> MeterUpdate -> Annex ()
|
|
|
|
readonlyStoreKey _ _ _ _ = readonlyFail
|
2015-08-17 15:21:38 +00:00
|
|
|
|
toward SafeDropProof expiry checking
Added Maybe POSIXTime to SafeDropProof, which gets set when the proof is
based on a LockedCopy. If there are several LockedCopies, it uses the
closest expiry time. That is not optimal, it may be that the proof
expires based on one LockedCopy but another one has not expired. But
that seems unlikely to really happen, and anyway the user can just
re-run a drop if it fails due to expiry.
Pass the SafeDropProof to removeKey, which is responsible for checking
it for expiry in situations where that could be a problem. Which really
only means in Remote.Git.
Made Remote.Git check expiry when dropping from a local remote.
Checking expiry when dropping from a P2P remote is not yet implemented.
P2P.Protocol.remove has SafeDropProof plumbed through to it for that
purpose.
Fixing the remaining 2 build warnings should complete this work.
Note that the use of a POSIXTime here means that if the clock gets set
forward while git-annex is in the middle of a drop, it may say that
dropping took too long. That seems ok. Less ok is that if the clock gets
turned back a sufficient amount (eg 5 minutes), proof expiry won't be
noticed. It might be better to use the Monotonic clock, but that doesn't
advance when a laptop is suspended, and while there is the linux
Boottime clock, that is not available on other systems. Perhaps a
combination of POSIXTime and the Monotonic clock could detect laptop
suspension and also detect clock being turned back?
There is a potential future flag day where
p2pDefaultLockContentRetentionDuration is not assumed, but is probed
using the P2P protocol, and peers that don't support it can no longer
produce a LockedCopy. Until that happens, when git-annex is
communicating with older peers there is a risk of data loss when
a ssh connection closes during LOCKCONTENT.
2024-07-04 16:23:46 +00:00
|
|
|
readonlyRemoveKey :: Maybe SafeDropProof -> Key -> Annex ()
|
|
|
|
readonlyRemoveKey _ _ = readonlyFail
|
2015-08-17 15:21:38 +00:00
|
|
|
|
|
|
|
readonlyStorer :: Storer
|
|
|
|
readonlyStorer _ _ _ = readonlyFail
|
|
|
|
|
2020-05-15 16:17:15 +00:00
|
|
|
readonlyStoreExport :: FilePath -> Key -> ExportLocation -> MeterUpdate -> Annex ()
|
|
|
|
readonlyStoreExport _ _ _ _ = readonlyFail
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2020-05-15 18:11:59 +00:00
|
|
|
readonlyRemoveExport :: Key -> ExportLocation -> Annex ()
|
|
|
|
readonlyRemoveExport _ _ = readonlyFail
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2020-05-15 18:32:45 +00:00
|
|
|
readonlyRemoveExportDirectory :: ExportDirectory -> Annex ()
|
|
|
|
readonlyRemoveExportDirectory _ = readonlyFail
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2020-05-15 16:17:15 +00:00
|
|
|
readonlyStoreExportWithContentIdentifier :: FilePath -> Key -> ExportLocation -> [ContentIdentifier] -> MeterUpdate -> Annex ContentIdentifier
|
|
|
|
readonlyStoreExportWithContentIdentifier _ _ _ _ _ = readonlyFail
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2020-05-15 18:11:59 +00:00
|
|
|
readonlyRemoveExportWithContentIdentifier :: Key -> ExportLocation -> [ContentIdentifier] -> Annex ()
|
|
|
|
readonlyRemoveExportWithContentIdentifier _ _ _ = readonlyFail
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2020-05-15 16:17:15 +00:00
|
|
|
readonlyFail :: Annex a
|
2020-05-13 18:03:00 +00:00
|
|
|
readonlyFail = giveup readonlyWarning
|
|
|
|
|
2019-08-13 16:05:00 +00:00
|
|
|
readonlyWarning :: String
|
|
|
|
readonlyWarning = "this remote is readonly"
|