mirror of
https://github.com/restic/restic.git
synced 2025-12-04 03:38:25 +00:00
Allow loading index with old format
This commit is contained in:
@@ -319,6 +319,19 @@ func (idx *Index) Dump(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// isErrOldIndex returns true if the error may be caused by an old index
|
||||
// format.
|
||||
func isErrOldIndex(err error) bool {
|
||||
if e, ok := err.(*json.UnmarshalTypeError); ok && e.Value == "array" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ErrOldIndexFormat means an index with the old format was detected.
|
||||
var ErrOldIndexFormat = errors.New("index has old format")
|
||||
|
||||
// DecodeIndex loads and unserializes an index from rd.
|
||||
func DecodeIndex(rd io.Reader) (*Index, backend.IDs, error) {
|
||||
debug.Log("Index.DecodeIndex", "Start decoding index")
|
||||
@@ -328,6 +341,12 @@ func DecodeIndex(rd io.Reader) (*Index, backend.IDs, error) {
|
||||
err := dec.Decode(&idxJSON)
|
||||
if err != nil {
|
||||
debug.Log("Index.DecodeIndex", "Error %#v", err)
|
||||
|
||||
if isErrOldIndex(err) {
|
||||
debug.Log("Index.DecodeIndex", "index is probably old format, trying that")
|
||||
err = ErrOldIndexFormat
|
||||
}
|
||||
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user