2013-08-29 22:51:22 +00:00
|
|
|
{- git-annex log file names
|
|
|
|
-
|
2018-08-31 16:23:22 +00:00
|
|
|
- Copyright 2013-2018 Joey Hess <id@joeyh.name>
|
2013-08-29 22:51:22 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
= UUIDBasedLog
|
|
|
|
| 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. -}
|
|
|
|
getLogVariety :: FilePath -> Maybe LogVariety
|
|
|
|
getLogVariety f
|
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
|
|
|
| f `elem` topLevelUUIDBasedLogs = Just UUIDBasedLog
|
|
|
|
| isRemoteStateLog f = Just NewUUIDBasedLog
|
2014-07-24 20:23:36 +00:00
|
|
|
| isChunkLog f = ChunkLog <$> chunkLogFileKey f
|
2018-09-05 17:20:10 +00:00
|
|
|
| isRemoteMetaDataLog f = Just RemoteMetaDataLog
|
|
|
|
| isMetaDataLog f || f `elem` otherLogs = Just OtherLog
|
2013-08-29 22:51:22 +00:00
|
|
|
| otherwise = PresenceLog <$> firstJust (presenceLogs f)
|
|
|
|
|
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
|
|
|
{- All the uuid-based logs stored in the top of the git-annex branch. -}
|
|
|
|
topLevelUUIDBasedLogs :: [FilePath]
|
|
|
|
topLevelUUIDBasedLogs =
|
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
|
2017-08-31 19:41:48 +00:00
|
|
|
, exportLog
|
2013-08-29 22:51:22 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
{- All the ways to get a key from a presence log file -}
|
|
|
|
presenceLogs :: FilePath -> [Maybe Key]
|
|
|
|
presenceLogs f =
|
|
|
|
[ urlLogFileKey f
|
|
|
|
, locationLogFileKey f
|
|
|
|
]
|
|
|
|
|
2014-03-15 17:44:31 +00:00
|
|
|
{- Logs that are neither UUID based nor presence logs. -}
|
|
|
|
otherLogs :: [FilePath]
|
|
|
|
otherLogs =
|
|
|
|
[ numcopiesLog
|
|
|
|
, groupPreferredContentLog
|
|
|
|
]
|
|
|
|
|
2013-08-29 22:51:22 +00:00
|
|
|
uuidLog :: FilePath
|
|
|
|
uuidLog = "uuid.log"
|
|
|
|
|
2014-01-20 20:47:56 +00:00
|
|
|
numcopiesLog :: FilePath
|
|
|
|
numcopiesLog = "numcopies.log"
|
|
|
|
|
2017-01-30 20:41:29 +00:00
|
|
|
configLog :: FilePath
|
|
|
|
configLog = "config.log"
|
|
|
|
|
2013-08-29 22:51:22 +00:00
|
|
|
remoteLog :: FilePath
|
|
|
|
remoteLog = "remote.log"
|
|
|
|
|
|
|
|
trustLog :: FilePath
|
|
|
|
trustLog = "trust.log"
|
|
|
|
|
|
|
|
groupLog :: FilePath
|
|
|
|
groupLog = "group.log"
|
|
|
|
|
|
|
|
preferredContentLog :: FilePath
|
|
|
|
preferredContentLog = "preferred-content.log"
|
|
|
|
|
2014-03-29 18:43:34 +00:00
|
|
|
requiredContentLog :: FilePath
|
|
|
|
requiredContentLog = "required-content.log"
|
|
|
|
|
2014-03-15 17:44:31 +00:00
|
|
|
groupPreferredContentLog :: FilePath
|
|
|
|
groupPreferredContentLog = "group-preferred-content.log"
|
|
|
|
|
2013-10-07 20:06:34 +00:00
|
|
|
scheduleLog :: FilePath
|
|
|
|
scheduleLog = "schedule.log"
|
|
|
|
|
2015-04-05 16:50:02 +00:00
|
|
|
activityLog :: FilePath
|
|
|
|
activityLog = "activity.log"
|
|
|
|
|
2015-01-27 21:38:06 +00:00
|
|
|
differenceLog :: FilePath
|
|
|
|
differenceLog = "difference.log"
|
|
|
|
|
2017-03-30 23:32:58 +00:00
|
|
|
multicastLog :: FilePath
|
|
|
|
multicastLog = "multicast.log"
|
2015-04-05 16:50:02 +00:00
|
|
|
|
2017-08-31 19:41:48 +00:00
|
|
|
exportLog :: FilePath
|
|
|
|
exportLog = "export.log"
|
|
|
|
|
2013-08-29 22:51:22 +00:00
|
|
|
{- The pathname of the location log file for a given key. -}
|
2015-01-28 21:17:26 +00:00
|
|
|
locationLogFile :: GitConfig -> Key -> String
|
|
|
|
locationLogFile config key = branchHashDir config key </> keyFile key ++ ".log"
|
2013-08-29 22:51:22 +00:00
|
|
|
|
|
|
|
{- Converts a pathname into a key if it's a location log. -}
|
|
|
|
locationLogFileKey :: FilePath -> Maybe Key
|
|
|
|
locationLogFileKey path
|
|
|
|
| ["remote", "web"] `isPrefixOf` splitDirectories dir = Nothing
|
2014-10-09 19:09:26 +00:00
|
|
|
| ext == ".log" = fileKey base
|
|
|
|
| otherwise = Nothing
|
2013-08-29 22:51:22 +00:00
|
|
|
where
|
|
|
|
(dir, file) = splitFileName path
|
2014-10-09 19:09:26 +00:00
|
|
|
(base, ext) = splitAt (length file - 4) file
|
2013-08-29 22:51:22 +00:00
|
|
|
|
|
|
|
{- The filename of the url log for a given key. -}
|
2015-01-28 21:17:26 +00:00
|
|
|
urlLogFile :: GitConfig -> Key -> FilePath
|
|
|
|
urlLogFile config key = branchHashDir config key </> keyFile key ++ urlLogExt
|
2013-08-29 22:51:22 +00:00
|
|
|
|
|
|
|
{- Old versions stored the urls elsewhere. -}
|
2015-01-28 21:17:26 +00:00
|
|
|
oldurlLogs :: GitConfig -> Key -> [FilePath]
|
|
|
|
oldurlLogs config key =
|
|
|
|
[ "remote/web" </> hdir </> key2file key ++ ".log"
|
|
|
|
, "remote/web" </> hdir </> 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
|
|
|
|
|
|
|
urlLogExt :: String
|
|
|
|
urlLogExt = ".log.web"
|
|
|
|
|
|
|
|
{- Converts a url log file into a key.
|
|
|
|
- (Does not work on oldurlLogs.) -}
|
|
|
|
urlLogFileKey :: FilePath -> Maybe Key
|
|
|
|
urlLogFileKey path
|
|
|
|
| ext == urlLogExt = fileKey base
|
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
file = takeFileName path
|
2013-08-29 22:51:22 +00:00
|
|
|
(base, ext) = splitAt (length file - extlen) file
|
|
|
|
extlen = length urlLogExt
|
|
|
|
|
|
|
|
{- Does not work on oldurllogs. -}
|
|
|
|
isUrlLog :: FilePath -> Bool
|
|
|
|
isUrlLog file = urlLogExt `isSuffixOf` file
|
|
|
|
|
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. -}
|
2015-01-28 21:17:26 +00:00
|
|
|
remoteStateLogFile :: GitConfig -> Key -> FilePath
|
|
|
|
remoteStateLogFile config key = branchHashDir config key
|
|
|
|
</> keyFile key ++ 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
|
|
|
|
|
|
|
remoteStateLogExt :: String
|
|
|
|
remoteStateLogExt = ".log.rmt"
|
|
|
|
|
|
|
|
isRemoteStateLog :: FilePath -> Bool
|
|
|
|
isRemoteStateLog path = remoteStateLogExt `isSuffixOf` path
|
|
|
|
|
2014-07-24 20:23:36 +00:00
|
|
|
{- The filename of the chunk log for a given key. -}
|
2015-01-28 21:17:26 +00:00
|
|
|
chunkLogFile :: GitConfig -> Key -> FilePath
|
|
|
|
chunkLogFile config key = branchHashDir config key </> keyFile key ++ chunkLogExt
|
2014-07-24 20:23:36 +00:00
|
|
|
|
|
|
|
chunkLogFileKey :: FilePath -> Maybe Key
|
|
|
|
chunkLogFileKey path
|
|
|
|
| ext == chunkLogExt = fileKey base
|
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
2014-10-09 18:53:13 +00:00
|
|
|
file = takeFileName path
|
2014-07-24 20:23:36 +00:00
|
|
|
(base, ext) = splitAt (length file - extlen) file
|
|
|
|
extlen = length chunkLogExt
|
|
|
|
|
|
|
|
chunkLogExt :: String
|
|
|
|
chunkLogExt = ".log.cnk"
|
|
|
|
|
|
|
|
isChunkLog :: FilePath -> Bool
|
|
|
|
isChunkLog path = chunkLogExt `isSuffixOf` path
|
|
|
|
|
2014-02-13 01:12:22 +00:00
|
|
|
{- The filename of the metadata log for a given key. -}
|
2015-01-28 21:17:26 +00:00
|
|
|
metaDataLogFile :: GitConfig -> Key -> FilePath
|
|
|
|
metaDataLogFile config key = branchHashDir config key </> keyFile key ++ metaDataLogExt
|
2014-02-13 01:12:22 +00:00
|
|
|
|
|
|
|
metaDataLogExt :: String
|
|
|
|
metaDataLogExt = ".log.met"
|
|
|
|
|
|
|
|
isMetaDataLog :: FilePath -> Bool
|
|
|
|
isMetaDataLog path = metaDataLogExt `isSuffixOf` path
|
2018-08-31 16:23:22 +00:00
|
|
|
|
|
|
|
{- The filename of the remote metadata log for a given key. -}
|
|
|
|
remoteMetaDataLogFile :: GitConfig -> Key -> FilePath
|
|
|
|
remoteMetaDataLogFile config key = branchHashDir config key </> keyFile key ++ remoteMetaDataLogExt
|
|
|
|
|
|
|
|
remoteMetaDataLogExt :: String
|
|
|
|
remoteMetaDataLogExt = ".log.rmet"
|
|
|
|
|
|
|
|
isRemoteMetaDataLog :: FilePath -> Bool
|
|
|
|
isRemoteMetaDataLog path = remoteMetaDataLogExt `isSuffixOf` path
|