mirror of
https://github.com/simon987/sist2.git
synced 2025-04-19 18:26:43 +00:00
Fix meta_key UB problem
This commit is contained in:
parent
81670ee107
commit
efa4a06e56
@ -18,7 +18,7 @@ typedef struct {
|
|||||||
#define META_NEXT 0xFFFF
|
#define META_NEXT 0xFFFF
|
||||||
|
|
||||||
void skip_meta(FILE *file) {
|
void skip_meta(FILE *file) {
|
||||||
enum metakey key;
|
enum metakey key = 0;
|
||||||
fread(&key, sizeof(uint16_t), 1, file);
|
fread(&key, sizeof(uint16_t), 1, file);
|
||||||
|
|
||||||
while (key != META_NEXT) {
|
while (key != META_NEXT) {
|
||||||
@ -237,7 +237,7 @@ void read_index_bin(const char *path, const char *index_id, index_func func) {
|
|||||||
FILE *file = fopen(path, "rb");
|
FILE *file = fopen(path, "rb");
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
buf.cur = 0;
|
buf.cur = 0;
|
||||||
size_t _ = fread((void *) &line, 1, sizeof(line_t), file);
|
size_t _ = fread((void *) &line, sizeof(line_t), 1, file);
|
||||||
if (feof(file)) {
|
if (feof(file)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -284,8 +284,8 @@ void read_index_bin(const char *path, const char *index_id, index_func func) {
|
|||||||
cJSON_AddStringToObject(document, "path", "");
|
cJSON_AddStringToObject(document, "path", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
enum metakey key;
|
enum metakey key = 0;
|
||||||
fread(&key, sizeof(short), 1, file);
|
fread(&key, sizeof(uint16_t), 1, file);
|
||||||
size_t ret;
|
size_t ret;
|
||||||
while (key != META_NEXT) {
|
while (key != META_NEXT) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@ -481,7 +481,7 @@ void incremental_read(GHashTable *table, const char *filepath) {
|
|||||||
|
|
||||||
incremental_put(table, line.path_md5, line.mtime);
|
incremental_put(table, line.path_md5, line.mtime);
|
||||||
|
|
||||||
while ((getc(file))) {}
|
while ((getc(file)) != 0) {}
|
||||||
skip_meta(file);
|
skip_meta(file);
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -531,7 +531,7 @@ void incremental_copy(store_t *store, store_t *dst_store, const char *filepath,
|
|||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum metakey key;
|
enum metakey key = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
fread(&key, sizeof(uint16_t), 1, file);
|
fread(&key, sizeof(uint16_t), 1, file);
|
||||||
fwrite(&key, sizeof(uint16_t), 1, dst_file);
|
fwrite(&key, sizeof(uint16_t), 1, dst_file);
|
||||||
|
@ -17,17 +17,19 @@ def copy_files(files):
|
|||||||
|
|
||||||
|
|
||||||
def sist2(*args):
|
def sist2(*args):
|
||||||
|
print("./sist2 " + " ".join(args))
|
||||||
|
|
||||||
return subprocess.check_output(
|
return subprocess.check_output(
|
||||||
args=["./sist2_debug", *args],
|
args=["./sist2", *args],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def sist2_index(files, *args):
|
def sist2_index(files, *args):
|
||||||
path = copy_files(files)
|
path = copy_files(files)
|
||||||
|
|
||||||
shutil.rmtree("i", ignore_errors=True)
|
shutil.rmtree("test_i", ignore_errors=True)
|
||||||
sist2("scan", path, "-o", "i", *args)
|
sist2("scan", path, "-o", "test_i", *args)
|
||||||
return iter(sist2_index_to_dict("i"))
|
return iter(sist2_index_to_dict("test_i"))
|
||||||
|
|
||||||
|
|
||||||
def sist2_incremental_index(files, func=None, *args):
|
def sist2_incremental_index(files, func=None, *args):
|
||||||
@ -36,14 +38,14 @@ def sist2_incremental_index(files, func=None, *args):
|
|||||||
if func:
|
if func:
|
||||||
func(path)
|
func(path)
|
||||||
|
|
||||||
shutil.rmtree("i_inc", ignore_errors=True)
|
shutil.rmtree("test_i_inc", ignore_errors=True)
|
||||||
sist2("scan", path, "-o", "i_inc", "--incremental", "i", *args)
|
sist2("scan", path, "-o", "test_i_inc", "--incremental", "test_i", *args)
|
||||||
return iter(sist2_index_to_dict("i_inc"))
|
return iter(sist2_index_to_dict("test_i_inc"))
|
||||||
|
|
||||||
|
|
||||||
def sist2_index_to_dict(index):
|
def sist2_index_to_dict(index):
|
||||||
res = subprocess.check_output(
|
res = subprocess.check_output(
|
||||||
args=["./sist2_debug", "index", "--print", index],
|
args=["./sist2", "index", "--print", index],
|
||||||
)
|
)
|
||||||
|
|
||||||
for line in res.splitlines():
|
for line in res.splitlines():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user