See #33
Unified · Split
| @@ -294,7 +294,7 @@ func (l *Log) load() error { · 293 unmodified lines | ||
| 294 | 294 | return err |
| 295 | 295 | } |
| 296 | 296 | l.lastIndex = lseg.index + uint64(len(lseg.epos)) - 1 |
| 297 | − if l.firstIndex > l.lastIndex && !l.opts.AllowEmpty { | |
| 297 | + if l.lastIndex > 0 && l.firstIndex > l.lastIndex && !l.opts.AllowEmpty { | |
| 298 | 298 | return ErrEmptyLog |
| 299 | 299 | } |
| 300 | 300 | return nil |
| @@ -1326,3 +1326,19 @@ func TestEmptyTruncateBackTwice(t *testing.T) { · 1325 unmodified lines | ||
| 1326 | 1326 | t.Fatalf("expected %v, got %v", true, empty) |
| 1327 | 1327 | } |
| 1328 | 1328 | } |
| 1329 | + | |
| 1330 | +func TestIssue33(t *testing.T) { | |
| 1331 | + // Create a fresh log without allowempty, close, and reopen. | |
| 1332 | + // This should not fail with an ErrEmptyLog | |
| 1333 | + os.RemoveAll("testlog") | |
| 1334 | + l, err := Open("log", nil) | |
| 1335 | + if err != nil { | |
| 1336 | + t.Fatal(err) | |
| 1337 | + } | |
| 1338 | + l.Close() | |
| 1339 | + l, err = Open("log", nil) | |
| 1340 | + if err != nil { | |
| 1341 | + t.Fatal(err) | |
| 1342 | + } | |
| 1343 | + l.Close() | |
| 1344 | +} | |