Automatically fix up badly formatted uuid.log entries produced by 3.20111105, whenever the uuid.log is changed (ie, by init or describe).
This commit is contained in:
parent
637b5feb45
commit
826d5887b2
3 changed files with 33 additions and 1 deletions
31
Logs/UUID.hs
31
Logs/UUID.hs
|
@ -36,7 +36,36 @@ describeUUID :: UUID -> String -> Annex ()
|
|||
describeUUID uuid desc = do
|
||||
ts <- liftIO getPOSIXTime
|
||||
Annex.Branch.change logfile $
|
||||
showLog id . changeLog ts uuid desc . parseLog Just
|
||||
showLog id . changeLog ts uuid desc . fixBadUUID . parseLog Just
|
||||
|
||||
{- Temporarily here to fix badly formatted uuid logs generated by
|
||||
- versions 3.20111105 and 3.20111025.
|
||||
-
|
||||
- Those logs contain entries with the UUID and description flipped.
|
||||
- Due to parsing, if the description is multiword, only the first
|
||||
- will be taken to be the UUID. So, if the UUID of an entry does
|
||||
- not look like a UUID, and the last word of the description does,
|
||||
- flip them back.
|
||||
-}
|
||||
fixBadUUID :: Log String -> Log String
|
||||
fixBadUUID = M.fromList . map fixup . M.toList
|
||||
where
|
||||
fixup (k, v)
|
||||
| isbad = (fixeduuid, LogEntry (Date $ newertime v) fixedvalue)
|
||||
| otherwise = (k, v)
|
||||
where
|
||||
kuuid = fromUUID k
|
||||
isbad = (not $ isuuid kuuid) && isuuid lastword
|
||||
ws = words $ value v
|
||||
lastword = last ws
|
||||
fixeduuid = toUUID lastword
|
||||
fixedvalue = unwords $ kuuid:(take (length ws - 1) ws)
|
||||
-- For the fixed line to take precidence, it should be
|
||||
-- slightly newer, but only slightly.
|
||||
newertime (LogEntry (Date d) _) = d + minimumPOSIXTimeSlice
|
||||
newertime (LogEntry (Unknown) _) = minimumPOSIXTimeSlice
|
||||
minimumPOSIXTimeSlice = 0.000001
|
||||
isuuid s = length s == 36 && length (split "-" s) == 5
|
||||
|
||||
{- Records the uuid in the log, if it's not already there. -}
|
||||
recordUUID :: UUID -> Annex ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue