| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | import os
|
|---|
| 4 | import xapian
|
|---|
| 5 |
|
|---|
| 6 | path="foo1"
|
|---|
| 7 | base_extn=".baseB"
|
|---|
| 8 |
|
|---|
| 9 | db = xapian.WritableDatabase(path, xapian.DB_CREATE_OR_OVERWRITE)
|
|---|
| 10 | doc = xapian.Document()
|
|---|
| 11 | # Database has full set of baseA, no baseB
|
|---|
| 12 |
|
|---|
| 13 | db.add_document(doc)
|
|---|
| 14 | db.flush()
|
|---|
| 15 |
|
|---|
| 16 | # Database has full set of baseB, old baseA
|
|---|
| 17 |
|
|---|
| 18 | db.add_document(doc)
|
|---|
| 19 | db.flush()
|
|---|
| 20 |
|
|---|
| 21 | # Database has full set of baseA, old baseB
|
|---|
| 22 | dbr = xapian.Database(path);
|
|---|
| 23 | print dbr.get_doccount()
|
|---|
| 24 |
|
|---|
| 25 | # Simulate a transaction starting, some of the baseB getting removed,
|
|---|
| 26 | # but then the transaction fails.
|
|---|
| 27 | os.unlink(os.path.join(path, 'record' + base_extn))
|
|---|
| 28 | os.unlink(os.path.join(path, 'termlist' + base_extn))
|
|---|
| 29 |
|
|---|
| 30 | # Database has full set of baseA, some old baseB
|
|---|
| 31 | dbr = xapian.Database(path);
|
|---|
| 32 | print dbr.get_doccount()
|
|---|
| 33 |
|
|---|
| 34 | db.add_document(doc)
|
|---|
| 35 | db.flush()
|
|---|
| 36 |
|
|---|
| 37 | # Database has full set of baseB, old baseA
|
|---|
| 38 |
|
|---|
| 39 | dbr = xapian.Database(path);
|
|---|
| 40 | print dbr.get_doccount()
|
|---|
| 41 |
|
|---|
| 42 | db.add_document(doc)
|
|---|
| 43 | db.flush()
|
|---|
| 44 |
|
|---|
| 45 | dbr = xapian.Database(path);
|
|---|
| 46 | print dbr.get_doccount()
|
|---|