equal
deleted
inserted
replaced
58 |
58 |
59 we use third-party library cbor to serialize data to write in the file. |
59 we use third-party library cbor to serialize data to write in the file. |
60 """ |
60 """ |
61 if not isinstance(version, int): |
61 if not isinstance(version, int): |
62 raise error.ProgrammingError( |
62 raise error.ProgrammingError( |
63 b"version of state file should be" b" an integer" |
63 b"version of state file should be an integer" |
64 ) |
64 ) |
65 |
65 |
66 with self._repo.vfs(self.fname, b'wb', atomictemp=True) as fp: |
66 with self._repo.vfs(self.fname, b'wb', atomictemp=True) as fp: |
67 fp.write(b'%d\n' % version) |
67 fp.write(b'%d\n' % version) |
68 for chunk in cborutil.streamencode(data): |
68 for chunk in cborutil.streamencode(data): |
74 with self._repo.vfs(self.fname, b'rb') as fp: |
74 with self._repo.vfs(self.fname, b'rb') as fp: |
75 try: |
75 try: |
76 int(fp.readline()) |
76 int(fp.readline()) |
77 except ValueError: |
77 except ValueError: |
78 raise error.CorruptedState( |
78 raise error.CorruptedState( |
79 b"unknown version of state file" b" found" |
79 b"unknown version of state file found" |
80 ) |
80 ) |
81 |
81 |
82 return cborutil.decodeall(fp.read())[0] |
82 return cborutil.decodeall(fp.read())[0] |
83 |
83 |
84 def delete(self): |
84 def delete(self): |