Commit 610c5880 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/fs1: Accept both FS21 and FS30 magics

FileStorage/py2 saves data with FS21 magic, while FileStorage/py3 with
FS30 magic:

https://github.com/zopefoundation/ZODB/blob/5.8.1/src/ZODB/_compat.py#L25-L77

Up till now FileStorage/go was accepting only FS21 and so with
py3-generated data it was leading to e.g. the following failure:

    === RUN   TestEmptyDB/py3_pickle3
        filestorage_test.go:90: testdata/py3_pickle3/empty.fs: invalid fs1 magic "FS30"

-> Fix it by accepting both py2 and py3 FileStorage magics.

We do accept them both without any other change because FileStorage
format, even when it comes with those two different magic, is really the
same.
parent 62ce629f
......@@ -87,9 +87,6 @@ func TestEmptyDB(t *testing.T) {
ztestdataReg.RunWithEach(t, _TestEmptyDB)
}
func _TestEmptyDB(t *testing.T, z *ZTestData) {
if z.Kind == "py3_pickle3" {
t.Skip("xfail")
}
fs, _ := xfsopen(t, z.Path("empty.fs"))
defer exc.XRun(fs.Close)
......@@ -100,9 +97,6 @@ func TestLoad(t *testing.T) {
ztestdataReg.RunWithEach(t, _TestLoad)
}
func _TestLoad(t *testing.T, z *ZTestData) {
if z.Kind == "py3_pickle3" {
t.Skip("xfail")
}
fs, _ := xfsopen(t, z.Path("1.fs"))
defer exc.XRun(fs.Close)
......@@ -247,9 +241,6 @@ func TestIterate(t *testing.T) {
ztestdataReg.RunWithEach(t, _TestIterate)
}
func _TestIterate(t *testing.T, z *ZTestData) {
if z.Kind == "py3_pickle3" {
t.Skip("xfail")
}
zz := z.Misc
fs, _ := xfsopen(t, z.Path("1.fs"))
......@@ -292,9 +283,6 @@ func BenchmarkIterate(b *testing.B) {
ztestdataReg.BenchWithEach(b, _BenchmarkIterate)
}
func _BenchmarkIterate(b *testing.B, z *ZTestData) {
if z.Kind == "py3_pickle3" {
b.Skip("xfail")
}
fs, _ := xfsopen(b, z.Path("1.fs"))
defer exc.XRun(fs.Close)
......@@ -347,9 +335,6 @@ func TestOpenRecovery(t *testing.T) {
ztestdataReg.RunWithEach(t, _TestOpenRecovery)
}
func _TestOpenRecovery(t *testing.T, z *ZTestData) {
if z.Kind == "py3_pickle3" {
t.Skip("xfail")
}
X := exc.Raiseif
zz := z.Misc
main, err := ioutil.ReadFile(z.Path("1.fs")); X(err)
......@@ -428,9 +413,6 @@ func TestLoadWhiteout(t *testing.T) {
ztestdataReg.RunWithEach(t, _TestLoadWhiteout)
}
func _TestLoadWhiteout(t *testing.T, z *ZTestData) {
if z.Kind == "py3_pickle3" {
t.Skip("xfail")
}
fs, _ := xfsopen(t, z.Path("whiteout.fs"))
defer exc.XRun(fs.Close)
......
// Copyright (C) 2017-2021 Nexedi SA and Contributors.
// Copyright (C) 2017-2024 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -68,7 +68,8 @@ type DataHeader struct {
}
const (
Magic = "FS21" // every FileStorage file starts with this
Magic21 = "FS21" // FileStorage file produced by Python2 starts with this
Magic30 = "FS30" // ----//---- by Python3
// on-disk sizes
FileHeaderSize = 4
......@@ -153,8 +154,12 @@ func (fh *FileHeader) Load(r io.ReaderAt) error {
if err != nil {
return fmt.Errorf("%sread magic: %s", ioprefix(r), err)
}
if string(fh.Magic[:]) != Magic {
switch string(fh.Magic[:]) {
default:
return fmt.Errorf("%sinvalid fs1 magic %q", ioprefix(r), fh.Magic)
case Magic21, Magic30:
// ok
}
return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment