/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-09 22:14:55 UTC
  • mto: This revision was merged to the branch mainline in revision 2341.
  • Revision ID: john@arbash-meinel.com-20070309221455-xh1sb3i6v07a7mak
Update _KnitData parser to raise more helpful errors when it detects corruption.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1427
1427
 
1428
1428
    def add_raw_record(self, raw_data):
1429
1429
        """Append a prepared record to the data file.
1430
 
        
 
1430
 
1431
1431
        :return: the offset in the data file raw_data was written.
1432
1432
        """
1433
1433
        assert isinstance(raw_data, str), 'data must be plain bytes'
1440
1440
                                   dir_mode=self._dir_mode)
1441
1441
            self._need_to_create = False
1442
1442
            return 0
1443
 
        
 
1443
 
1444
1444
    def add_record(self, version_id, digest, lines):
1445
1445
        """Write new text record to disk.  Returns the position in the
1446
1446
        file where it was written."""
1466
1466
                 as (stream, header_record)
1467
1467
        """
1468
1468
        df = GzipFile(mode='rb', fileobj=StringIO(raw_data))
1469
 
        rec = self._check_header(version_id, df.readline())
 
1469
        try:
 
1470
            rec = self._check_header(version_id, df.readline())
 
1471
        except Exception, e:
 
1472
            raise KnitCorrupt(self._filename,
 
1473
                              "While reading {%s} got %s(%s)"
 
1474
                              % (version_id, e.__class__.__name__, str(e)))
1470
1475
        return df, rec
1471
1476
 
1472
1477
    def _check_header(self, version_id, line):
1487
1492
        # 4168 calls to readlines in 330
1488
1493
        df = GzipFile(mode='rb', fileobj=StringIO(data))
1489
1494
 
1490
 
        record_contents = df.readlines()
 
1495
        try:
 
1496
            record_contents = df.readlines()
 
1497
        except Exception, e:
 
1498
            raise KnitCorrupt(self._filename,
 
1499
                              "While reading {%s} got %s(%s)"
 
1500
                              % (version_id, e.__class__.__name__, str(e)))
1491
1501
        header = record_contents.pop(0)
1492
1502
        rec = self._check_header(version_id, header)
1493
1503
 
1494
1504
        last_line = record_contents.pop()
1495
 
        assert len(record_contents) == int(rec[2])
 
1505
        if len(record_contents) != int(rec[2]):
 
1506
            raise KnitCorrupt(self._filename,
 
1507
                              'incorrect number of lines %s != %s'
 
1508
                              ' for version {%s}'
 
1509
                              % (len(record_contents), int(rec[2]),
 
1510
                                 version_id))
1496
1511
        if last_line != 'end %s\n' % rec[1]:
1497
1512
            raise KnitCorrupt(self._filename,
1498
1513
                              'unexpected version end line %r, wanted %r'