~ubuntu-branches/ubuntu/oneiric/ubuntuone-client/oneiric

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/tritcask.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-23 18:34:09 UTC
  • mfrom: (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110223183409-535o7yo165wbjmca
Tags: 1.5.5-0ubuntu1
* New upstream release.
  - Subscribing to a RO share will not download content (LP: #712528)
  - Can't synchronize "~/Ubuntu One Music" (LP: #714976)
  - Syncdaemon needs to show progress in Unity launcher (LP: #702116)
  - Notifications say "your cloud" (LP: #715887)
  - No longer requires python-libproxy
  - Recommend unity and indicator libs by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    """A Exception for Bad CRC32."""
71
71
 
72
72
 
 
73
class BadHeader(Exception):
 
74
    """A Exception for Bad header value."""
 
75
 
73
76
TritcaskEntry = namedtuple('TritcaskEntry', ['crc32', 'tstamp', 'key_sz',
74
77
                         'value_sz', 'row_type', 'key', 'value', 'value_pos'])
75
78
 
144
147
        If filename is None a new file is created.
145
148
        """
146
149
        self.has_bad_crc = False
 
150
        self.has_bad_data = False
147
151
        if filename is None:
148
152
            filename = self._get_next_file_id() + LIVE + FILE_SUFFIX
149
153
        self.filename = os.path.join(base_path, filename)
213
217
                               'the rest of the file will be ignored.',
214
218
                               self.file_id, current_pos)
215
219
                raise StopIteration
 
220
            except BadHeader:
 
221
                self.has_bad_data = True
 
222
                logger.warning('Found corrupted header on %s at position: %s, '
 
223
                               'the rest of the file will be ignored.',
 
224
                               self.file_id, current_pos)
 
225
                raise StopIteration
216
226
 
217
227
    def __getitem__(self, item):
218
228
        """__getitem__ to support slicing and *only* slicing."""
249
259
        if header == '' or crc32_bytes == '':
250
260
            # reached EOF
251
261
            raise EOFError
252
 
        crc32 = crc32_struct.unpack(crc32_bytes)[0]
253
 
        tstamp, key_sz, value_sz, row_type = header_struct.unpack(header)
 
262
        try:
 
263
            crc32 = crc32_struct.unpack(crc32_bytes)[0]
 
264
            tstamp, key_sz, value_sz, row_type = header_struct.unpack(header)
 
265
        except struct.error, e:
 
266
            raise BadHeader(e)
254
267
        key = fmmap[current_pos:current_pos+key_sz]
255
268
        current_pos += key_sz
256
269
        value_pos = current_pos
586
599
            return False
587
600
        # check if the file is marked with a bad crc
588
601
        # as we shouldn't keep adding data to a broken file.
589
 
        if self.live_file.has_bad_crc:
 
602
        if self.live_file.has_bad_crc or self.live_file.has_bad_data:
590
603
            return True
591
604
        # now check the default rotation policy
592
605
        try: