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
|
|
|
|
, renameExport = readonlyRenameExport
|
|
|
|
}
|
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
|
|
|
|
|
|
|
readonlyStoreKey :: Key -> AssociatedFile -> MeterUpdate -> Annex Bool
|
|
|
|
readonlyStoreKey _ _ _ = readonlyFail
|
|
|
|
|
|
|
|
readonlyRemoveKey :: Key -> Annex Bool
|
|
|
|
readonlyRemoveKey _ = readonlyFail
|
|
|
|
|
|
|
|
readonlyStorer :: Storer
|
|
|
|
readonlyStorer _ _ _ = readonlyFail
|
|
|
|
|
2019-05-28 15:04:28 +00:00
|
|
|
readonlyStoreExport :: FilePath -> Key -> ExportLocation -> MeterUpdate -> Annex Bool
|
|
|
|
readonlyStoreExport _ _ _ _ = readonlyFail
|
|
|
|
|
|
|
|
readonlyRemoveExport :: Key -> ExportLocation -> Annex Bool
|
|
|
|
readonlyRemoveExport _ _ = readonlyFail
|
|
|
|
|
|
|
|
readonlyRemoveExportDirectory :: ExportDirectory -> Annex Bool
|
|
|
|
readonlyRemoveExportDirectory _ = readonlyFail
|
|
|
|
|
|
|
|
readonlyRenameExport :: Key -> ExportLocation -> ExportLocation -> Annex (Maybe Bool)
|
|
|
|
readonlyRenameExport _ _ _ = return Nothing
|
|
|
|
|
2019-08-13 16:05:00 +00:00
|
|
|
readonlyStoreExportWithContentIdentifier :: FilePath -> Key -> ExportLocation -> [ContentIdentifier] -> MeterUpdate -> Annex (Either String ContentIdentifier)
|
|
|
|
readonlyStoreExportWithContentIdentifier _ _ _ _ _ =
|
|
|
|
return $ Left readonlyWarning
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2019-05-28 15:17:25 +00:00
|
|
|
readonlyRemoveExportWithContentIdentifier :: Key -> ExportLocation -> [ContentIdentifier] -> Annex Bool
|
|
|
|
readonlyRemoveExportWithContentIdentifier _ _ _ = readonlyFail
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2015-08-17 15:21:38 +00:00
|
|
|
readonlyFail :: Annex Bool
|
|
|
|
readonlyFail = do
|
2019-08-13 16:05:00 +00:00
|
|
|
warning readonlyWarning
|
2015-08-17 15:21:38 +00:00
|
|
|
return False
|
2019-05-28 15:04:28 +00:00
|
|
|
|
2019-08-13 16:05:00 +00:00
|
|
|
readonlyWarning :: String
|
|
|
|
readonlyWarning = "this remote is readonly"
|