mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-19 18:36:07 +00:00
Merge pull request #47 from ThomasWaldmann/magic-length
don't hardcode MAGIC length
This commit is contained in:
commit
c97a353356
2 changed files with 9 additions and 6 deletions
|
@ -18,8 +18,11 @@
|
|||
#error Unknown byte order
|
||||
#endif
|
||||
|
||||
#define MAGIC "BORG_IDX"
|
||||
#define MAGIC_LEN 8
|
||||
|
||||
typedef struct {
|
||||
char magic[8];
|
||||
char magic[MAGIC_LEN];
|
||||
int32_t num_entries;
|
||||
int32_t num_buckets;
|
||||
int8_t key_size;
|
||||
|
@ -37,7 +40,6 @@ typedef struct {
|
|||
int upper_limit;
|
||||
} HashIndex;
|
||||
|
||||
#define MAGIC "BORG_IDX"
|
||||
#define EMPTY _htole32(0xffffffff)
|
||||
#define DELETED _htole32(0xfffffffe)
|
||||
#define MAX_BUCKET_SIZE 512
|
||||
|
@ -162,7 +164,7 @@ hashindex_read(const char *path)
|
|||
EPRINTF_PATH(path, "fseek failed");
|
||||
goto fail;
|
||||
}
|
||||
if(memcmp(header.magic, MAGIC, 8)) {
|
||||
if(memcmp(header.magic, MAGIC, MAGIC_LEN)) {
|
||||
EPRINTF_MSG_PATH(path, "Unknown MAGIC in header");
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ from .lrucache import LRUCache
|
|||
|
||||
MAX_OBJECT_SIZE = 20 * 1024 * 1024
|
||||
MAGIC = b'BORG_SEG'
|
||||
MAGIC_LEN = len(MAGIC)
|
||||
TAG_PUT = 0
|
||||
TAG_DELETE = 1
|
||||
TAG_COMMIT = 2
|
||||
|
@ -481,7 +482,7 @@ class LoggedIO:
|
|||
os.mkdir(dirname)
|
||||
self._write_fd = open(self.segment_filename(self.segment), 'ab')
|
||||
self._write_fd.write(MAGIC)
|
||||
self.offset = 8
|
||||
self.offset = MAGIC_LEN
|
||||
return self._write_fd
|
||||
|
||||
def get_fd(self, segment):
|
||||
|
@ -504,9 +505,9 @@ class LoggedIO:
|
|||
def iter_objects(self, segment, include_data=False):
|
||||
fd = self.get_fd(segment)
|
||||
fd.seek(0)
|
||||
if fd.read(8) != MAGIC:
|
||||
if fd.read(MAGIC_LEN) != MAGIC:
|
||||
raise IntegrityError('Invalid segment header')
|
||||
offset = 8
|
||||
offset = MAGIC_LEN
|
||||
header = fd.read(self.header_fmt.size)
|
||||
while header:
|
||||
crc, size, tag = self.header_fmt.unpack(header)
|
||||
|
|
Loading…
Add table
Reference in a new issue