2013-08-29 22:51:22 +00:00
|
|
|
{- git-annex log file names
|
|
|
|
-
|
2020-02-14 19:22:48 +00:00
|
|
|
- Copyright 2013-2020 Joey Hess <id@joeyh.name>
|
2013-08-29 22:51:22 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-08-29 22:51:22 +00:00
|
|
|
-}
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2013-08-29 22:51:22 +00:00
|
|
|
module Logs where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2015-01-28 21:17:26 +00:00
|
|
|
import Annex.DirHashes
|
2013-08-29 22:51:22 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
import qualified Data.ByteString as S
|
2019-12-11 18:12:22 +00:00
|
|
|
import qualified System.FilePath.ByteString as P
|
2019-11-26 19:27:22 +00:00
|
|
|
|
add remote state logs
This allows a remote to store a piece of arbitrary state associated with a
key. This is needed to support Tahoe, where the file-cap is calculated from
the data stored in it, and used to retrieve a key later. Glacier also would
be much improved by using this.
GETSTATE and SETSTATE are added to the external special remote protocol.
Note that the state is left as-is even when a key is removed from a remote.
It's up to the remote to decide when it wants to clear the state.
The remote state log, $KEY.log.rmt, is a UUID-based log. However,
rather than using the old UUID-based log format, I created a new variant
of that format. The new varient is more space efficient (since it lacks the
"timestamp=" hack, and easier to parse (and the parser doesn't mess with
whitespace in the value), and avoids compatability cruft in the old one.
This seemed worth cleaning up for these new files, since there could be a
lot of them, while before UUID-based logs were only used for a few log
files at the top of the git-annex branch. The transition code has also
been updated to handle these new UUID-based logs.
This commit was sponsored by Daniel Hofer.
2014-01-03 20:35:57 +00:00
|
|
|
{- There are several varieties of log file formats. -}
|
2014-01-20 20:47:56 +00:00
|
|
|
data LogVariety
|
2019-02-21 17:43:21 +00:00
|
|
|
= OldUUIDBasedLog
|
2014-01-20 20:47:56 +00:00
|
|
|
| NewUUIDBasedLog
|
2014-07-24 20:23:36 +00:00
|
|
|
| ChunkLog Key
|
2014-01-20 20:47:56 +00:00
|
|
|
| PresenceLog Key
|
2018-09-05 17:20:10 +00:00
|
|
|
| RemoteMetaDataLog
|
2014-02-13 01:12:22 +00:00
|
|
|
| OtherLog
|
2013-08-29 22:51:22 +00:00
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
{- Converts a path from the git-annex branch into one of the varieties
|
|
|
|
- of logs used by git-annex, if it's a known path. -}
|
2020-02-14 19:22:48 +00:00
|
|
|
getLogVariety :: GitConfig -> RawFilePath -> Maybe LogVariety
|
|
|
|
getLogVariety config f
|
2019-02-21 17:43:21 +00:00
|
|
|
| f `elem` topLevelOldUUIDBasedLogs = Just OldUUIDBasedLog
|
2019-02-23 01:34:31 +00:00
|
|
|
| f `elem` topLevelNewUUIDBasedLogs = Just NewUUIDBasedLog
|
|
|
|
| isRemoteStateLog f = Just NewUUIDBasedLog
|
|
|
|
| isRemoteContentIdentifierLog f = Just NewUUIDBasedLog
|
2019-03-06 21:48:46 +00:00
|
|
|
| isChunkLog f = ChunkLog <$> extLogFileKey chunkLogExt f
|
2018-09-05 17:20:10 +00:00
|
|
|
| isRemoteMetaDataLog f = Just RemoteMetaDataLog
|
|
|
|
| isMetaDataLog f || f `elem` otherLogs = Just OtherLog
|
2020-02-14 19:22:48 +00:00
|
|
|
| otherwise = PresenceLog <$> firstJust (presenceLogs config f)
|
2013-08-29 22:51:22 +00:00
|
|
|
|
2019-02-23 01:34:31 +00:00
|
|
|
{- All the old-format uuid-based logs stored in the top of the git-annex branch. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
topLevelOldUUIDBasedLogs :: [RawFilePath]
|
2019-02-21 17:43:21 +00:00
|
|
|
topLevelOldUUIDBasedLogs =
|
2013-08-29 22:51:22 +00:00
|
|
|
[ uuidLog
|
|
|
|
, remoteLog
|
|
|
|
, trustLog
|
|
|
|
, groupLog
|
|
|
|
, preferredContentLog
|
2014-03-29 18:43:34 +00:00
|
|
|
, requiredContentLog
|
2013-10-07 20:06:34 +00:00
|
|
|
, scheduleLog
|
2015-04-05 16:50:02 +00:00
|
|
|
, activityLog
|
2015-01-27 21:38:06 +00:00
|
|
|
, differenceLog
|
2017-03-30 23:32:58 +00:00
|
|
|
, multicastLog
|
2013-08-29 22:51:22 +00:00
|
|
|
]
|
|
|
|
|
2019-02-23 01:34:31 +00:00
|
|
|
{- All the new-format uuid-based logs stored in the top of the git-annex branch. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
topLevelNewUUIDBasedLogs :: [RawFilePath]
|
2019-02-23 01:34:31 +00:00
|
|
|
topLevelNewUUIDBasedLogs =
|
|
|
|
[ exportLog
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2013-08-29 22:51:22 +00:00
|
|
|
{- All the ways to get a key from a presence log file -}
|
2020-02-14 19:22:48 +00:00
|
|
|
presenceLogs :: GitConfig -> RawFilePath -> [Maybe Key]
|
|
|
|
presenceLogs config f =
|
2013-08-29 22:51:22 +00:00
|
|
|
[ urlLogFileKey f
|
2020-02-14 19:22:48 +00:00
|
|
|
, locationLogFileKey config f
|
2013-08-29 22:51:22 +00:00
|
|
|
]
|
|
|
|
|
2019-02-20 19:36:09 +00:00
|
|
|
{- Top-level logs that are neither UUID based nor presence logs. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
otherLogs :: [RawFilePath]
|
2014-03-15 17:44:31 +00:00
|
|
|
otherLogs =
|
|
|
|
[ numcopiesLog
|
|
|
|
, groupPreferredContentLog
|
|
|
|
]
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
uuidLog :: RawFilePath
|
2013-08-29 22:51:22 +00:00
|
|
|
uuidLog = "uuid.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
numcopiesLog :: RawFilePath
|
2014-01-20 20:47:56 +00:00
|
|
|
numcopiesLog = "numcopies.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
configLog :: RawFilePath
|
2017-01-30 20:41:29 +00:00
|
|
|
configLog = "config.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteLog :: RawFilePath
|
2013-08-29 22:51:22 +00:00
|
|
|
remoteLog = "remote.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
trustLog :: RawFilePath
|
2013-08-29 22:51:22 +00:00
|
|
|
trustLog = "trust.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
groupLog :: RawFilePath
|
2013-08-29 22:51:22 +00:00
|
|
|
groupLog = "group.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
preferredContentLog :: RawFilePath
|
2013-08-29 22:51:22 +00:00
|
|
|
preferredContentLog = "preferred-content.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
requiredContentLog :: RawFilePath
|
2014-03-29 18:43:34 +00:00
|
|
|
requiredContentLog = "required-content.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
groupPreferredContentLog :: RawFilePath
|
2014-03-15 17:44:31 +00:00
|
|
|
groupPreferredContentLog = "group-preferred-content.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
scheduleLog :: RawFilePath
|
2013-10-07 20:06:34 +00:00
|
|
|
scheduleLog = "schedule.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
activityLog :: RawFilePath
|
2015-04-05 16:50:02 +00:00
|
|
|
activityLog = "activity.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
differenceLog :: RawFilePath
|
2015-01-27 21:38:06 +00:00
|
|
|
differenceLog = "difference.log"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
multicastLog :: RawFilePath
|
2017-03-30 23:32:58 +00:00
|
|
|
multicastLog = "multicast.log"
|
2015-04-05 16:50:02 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
exportLog :: RawFilePath
|
2017-08-31 19:41:48 +00:00
|
|
|
exportLog = "export.log"
|
|
|
|
|
2013-08-29 22:51:22 +00:00
|
|
|
{- The pathname of the location log file for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
locationLogFile :: GitConfig -> Key -> RawFilePath
|
2019-12-11 18:12:22 +00:00
|
|
|
locationLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
branchHashDir config key P.</> keyFile key <> ".log"
|
2013-08-29 22:51:22 +00:00
|
|
|
|
|
|
|
{- The filename of the url log for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
urlLogFile :: GitConfig -> Key -> RawFilePath
|
2019-12-11 18:12:22 +00:00
|
|
|
urlLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
branchHashDir config key P.</> keyFile key <> urlLogExt
|
2013-08-29 22:51:22 +00:00
|
|
|
|
|
|
|
{- Old versions stored the urls elsewhere. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
oldurlLogs :: GitConfig -> Key -> [RawFilePath]
|
2019-12-11 18:12:22 +00:00
|
|
|
oldurlLogs config key =
|
|
|
|
[ "remote/web" P.</> hdir P.</> serializeKey' key <> ".log"
|
2019-12-18 20:45:03 +00:00
|
|
|
, "remote/web" P.</> hdir P.</> keyFile key <> ".log"
|
2013-08-29 22:51:22 +00:00
|
|
|
]
|
2015-01-28 21:17:26 +00:00
|
|
|
where
|
|
|
|
hdir = branchHashDir config key
|
2013-08-29 22:51:22 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
urlLogExt :: S.ByteString
|
2013-08-29 22:51:22 +00:00
|
|
|
urlLogExt = ".log.web"
|
|
|
|
|
|
|
|
{- Does not work on oldurllogs. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
isUrlLog :: RawFilePath -> Bool
|
|
|
|
isUrlLog file = urlLogExt `S.isSuffixOf` file
|
2013-08-29 22:51:22 +00:00
|
|
|
|
add remote state logs
This allows a remote to store a piece of arbitrary state associated with a
key. This is needed to support Tahoe, where the file-cap is calculated from
the data stored in it, and used to retrieve a key later. Glacier also would
be much improved by using this.
GETSTATE and SETSTATE are added to the external special remote protocol.
Note that the state is left as-is even when a key is removed from a remote.
It's up to the remote to decide when it wants to clear the state.
The remote state log, $KEY.log.rmt, is a UUID-based log. However,
rather than using the old UUID-based log format, I created a new variant
of that format. The new varient is more space efficient (since it lacks the
"timestamp=" hack, and easier to parse (and the parser doesn't mess with
whitespace in the value), and avoids compatability cruft in the old one.
This seemed worth cleaning up for these new files, since there could be a
lot of them, while before UUID-based logs were only used for a few log
files at the top of the git-annex branch. The transition code has also
been updated to handle these new UUID-based logs.
This commit was sponsored by Daniel Hofer.
2014-01-03 20:35:57 +00:00
|
|
|
{- The filename of the remote state log for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteStateLogFile :: GitConfig -> Key -> RawFilePath
|
|
|
|
remoteStateLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
(branchHashDir config key P.</> keyFile key)
|
2019-11-26 19:27:22 +00:00
|
|
|
<> remoteStateLogExt
|
add remote state logs
This allows a remote to store a piece of arbitrary state associated with a
key. This is needed to support Tahoe, where the file-cap is calculated from
the data stored in it, and used to retrieve a key later. Glacier also would
be much improved by using this.
GETSTATE and SETSTATE are added to the external special remote protocol.
Note that the state is left as-is even when a key is removed from a remote.
It's up to the remote to decide when it wants to clear the state.
The remote state log, $KEY.log.rmt, is a UUID-based log. However,
rather than using the old UUID-based log format, I created a new variant
of that format. The new varient is more space efficient (since it lacks the
"timestamp=" hack, and easier to parse (and the parser doesn't mess with
whitespace in the value), and avoids compatability cruft in the old one.
This seemed worth cleaning up for these new files, since there could be a
lot of them, while before UUID-based logs were only used for a few log
files at the top of the git-annex branch. The transition code has also
been updated to handle these new UUID-based logs.
This commit was sponsored by Daniel Hofer.
2014-01-03 20:35:57 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteStateLogExt :: S.ByteString
|
add remote state logs
This allows a remote to store a piece of arbitrary state associated with a
key. This is needed to support Tahoe, where the file-cap is calculated from
the data stored in it, and used to retrieve a key later. Glacier also would
be much improved by using this.
GETSTATE and SETSTATE are added to the external special remote protocol.
Note that the state is left as-is even when a key is removed from a remote.
It's up to the remote to decide when it wants to clear the state.
The remote state log, $KEY.log.rmt, is a UUID-based log. However,
rather than using the old UUID-based log format, I created a new variant
of that format. The new varient is more space efficient (since it lacks the
"timestamp=" hack, and easier to parse (and the parser doesn't mess with
whitespace in the value), and avoids compatability cruft in the old one.
This seemed worth cleaning up for these new files, since there could be a
lot of them, while before UUID-based logs were only used for a few log
files at the top of the git-annex branch. The transition code has also
been updated to handle these new UUID-based logs.
This commit was sponsored by Daniel Hofer.
2014-01-03 20:35:57 +00:00
|
|
|
remoteStateLogExt = ".log.rmt"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
isRemoteStateLog :: RawFilePath -> Bool
|
|
|
|
isRemoteStateLog path = remoteStateLogExt `S.isSuffixOf` path
|
add remote state logs
This allows a remote to store a piece of arbitrary state associated with a
key. This is needed to support Tahoe, where the file-cap is calculated from
the data stored in it, and used to retrieve a key later. Glacier also would
be much improved by using this.
GETSTATE and SETSTATE are added to the external special remote protocol.
Note that the state is left as-is even when a key is removed from a remote.
It's up to the remote to decide when it wants to clear the state.
The remote state log, $KEY.log.rmt, is a UUID-based log. However,
rather than using the old UUID-based log format, I created a new variant
of that format. The new varient is more space efficient (since it lacks the
"timestamp=" hack, and easier to parse (and the parser doesn't mess with
whitespace in the value), and avoids compatability cruft in the old one.
This seemed worth cleaning up for these new files, since there could be a
lot of them, while before UUID-based logs were only used for a few log
files at the top of the git-annex branch. The transition code has also
been updated to handle these new UUID-based logs.
This commit was sponsored by Daniel Hofer.
2014-01-03 20:35:57 +00:00
|
|
|
|
2014-07-24 20:23:36 +00:00
|
|
|
{- The filename of the chunk log for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
chunkLogFile :: GitConfig -> Key -> RawFilePath
|
|
|
|
chunkLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
(branchHashDir config key P.</> keyFile key)
|
2019-11-26 19:27:22 +00:00
|
|
|
<> chunkLogExt
|
2014-07-24 20:23:36 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
chunkLogExt :: S.ByteString
|
2014-07-24 20:23:36 +00:00
|
|
|
chunkLogExt = ".log.cnk"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
isChunkLog :: RawFilePath -> Bool
|
|
|
|
isChunkLog path = chunkLogExt `S.isSuffixOf` path
|
2014-07-24 20:23:36 +00:00
|
|
|
|
2014-02-13 01:12:22 +00:00
|
|
|
{- The filename of the metadata log for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
metaDataLogFile :: GitConfig -> Key -> RawFilePath
|
|
|
|
metaDataLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
(branchHashDir config key P.</> keyFile key)
|
2019-11-26 19:27:22 +00:00
|
|
|
<> metaDataLogExt
|
2014-02-13 01:12:22 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
metaDataLogExt :: S.ByteString
|
2014-02-13 01:12:22 +00:00
|
|
|
metaDataLogExt = ".log.met"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
isMetaDataLog :: RawFilePath -> Bool
|
|
|
|
isMetaDataLog path = metaDataLogExt `S.isSuffixOf` path
|
2018-08-31 16:23:22 +00:00
|
|
|
|
|
|
|
{- The filename of the remote metadata log for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteMetaDataLogFile :: GitConfig -> Key -> RawFilePath
|
|
|
|
remoteMetaDataLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
(branchHashDir config key P.</> keyFile key)
|
2019-11-26 19:27:22 +00:00
|
|
|
<> remoteMetaDataLogExt
|
2018-08-31 16:23:22 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteMetaDataLogExt :: S.ByteString
|
2018-08-31 16:23:22 +00:00
|
|
|
remoteMetaDataLogExt = ".log.rmet"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
isRemoteMetaDataLog :: RawFilePath -> Bool
|
|
|
|
isRemoteMetaDataLog path = remoteMetaDataLogExt `S.isSuffixOf` path
|
2019-02-20 19:36:09 +00:00
|
|
|
|
|
|
|
{- The filename of the remote content identifier log for a given key. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteContentIdentifierLogFile :: GitConfig -> Key -> RawFilePath
|
|
|
|
remoteContentIdentifierLogFile config key =
|
2019-12-18 20:45:03 +00:00
|
|
|
(branchHashDir config key P.</> keyFile key)
|
2019-11-26 19:27:22 +00:00
|
|
|
<> remoteContentIdentifierExt
|
2019-02-20 19:36:09 +00:00
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
remoteContentIdentifierExt :: S.ByteString
|
2019-02-20 19:36:09 +00:00
|
|
|
remoteContentIdentifierExt = ".log.cid"
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
isRemoteContentIdentifierLog :: RawFilePath -> Bool
|
|
|
|
isRemoteContentIdentifierLog path = remoteContentIdentifierExt `S.isSuffixOf` path
|
2019-03-06 21:48:46 +00:00
|
|
|
|
|
|
|
{- From an extension and a log filename, get the key that it's a log for. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
extLogFileKey :: S.ByteString -> RawFilePath -> Maybe Key
|
2019-03-06 21:48:46 +00:00
|
|
|
extLogFileKey expectedext path
|
2020-07-07 17:03:33 +00:00
|
|
|
| ext == expectedext = fileKey base
|
2019-03-06 21:48:46 +00:00
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
2020-07-07 17:03:33 +00:00
|
|
|
file = P.takeFileName path
|
|
|
|
(base, ext) = S.splitAt (S.length file - extlen) file
|
2019-11-26 19:27:22 +00:00
|
|
|
extlen = S.length expectedext
|
2019-03-06 21:48:46 +00:00
|
|
|
|
|
|
|
{- Converts a url log file into a key.
|
|
|
|
- (Does not work on oldurlLogs.) -}
|
2019-11-26 19:27:22 +00:00
|
|
|
urlLogFileKey :: RawFilePath -> Maybe Key
|
2019-03-06 21:48:46 +00:00
|
|
|
urlLogFileKey = extLogFileKey urlLogExt
|
|
|
|
|
|
|
|
{- Converts a pathname into a key if it's a location log. -}
|
2020-02-14 19:22:48 +00:00
|
|
|
locationLogFileKey :: GitConfig -> RawFilePath -> Maybe Key
|
|
|
|
locationLogFileKey config path
|
|
|
|
| length (splitDirectories (fromRawFilePath path)) /= locationLogFileDepth config = Nothing
|
2019-03-06 21:48:46 +00:00
|
|
|
| otherwise = extLogFileKey ".log" path
|
2020-02-14 19:22:48 +00:00
|
|
|
|
|
|
|
{- Depth of location log files within the git-annex branch.
|
|
|
|
-
|
|
|
|
- Normally they are xx/yy/key.log so depth 3.
|
|
|
|
- The same extension is also used for other logs that
|
|
|
|
- are not location logs. -}
|
|
|
|
locationLogFileDepth :: GitConfig -> Int
|
|
|
|
locationLogFileDepth config = hashlevels + 1
|
|
|
|
where
|
|
|
|
HashLevels hashlevels = branchHashLevels config
|