refactor(tree)!: renamed the save_tree function to snapshot_tree
This commit is contained in:
parent
e63fb4a0fa
commit
983c6d4ca4
2 changed files with 5 additions and 9 deletions
|
|
@ -8,6 +8,6 @@
|
||||||
|
|
||||||
typedef List FileInfoBuffer;
|
typedef List FileInfoBuffer;
|
||||||
|
|
||||||
void save_tree(PathBuffer*);
|
void snapshot_tree(PathBuffer*);
|
||||||
|
|
||||||
#endif // TREE_H
|
#endif // TREE_H
|
||||||
|
|
|
||||||
12
src/tree.c
12
src/tree.c
|
|
@ -1,6 +1,6 @@
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
void save_tree(PathBuffer* tree) {
|
void snapshot_tree(PathBuffer* tree) {
|
||||||
PathBuffer* files = path_buffer_new();
|
PathBuffer* files = path_buffer_new();
|
||||||
char relative[PATH_MAX] = "";
|
char relative[PATH_MAX] = "";
|
||||||
char* root = find_root(relative);
|
char* root = find_root(relative);
|
||||||
|
|
@ -13,10 +13,6 @@ void save_tree(PathBuffer* tree) {
|
||||||
walk(root, relative, relative, files, 1, root);
|
walk(root, relative, relative, files, 1, root);
|
||||||
path_buffer_sort(files);
|
path_buffer_sort(files);
|
||||||
|
|
||||||
for (int i = 0; i < files->len; i++) {
|
|
||||||
printf("%s\n", files->items[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
|
||||||
|
|
@ -27,7 +23,7 @@ void save_tree(PathBuffer* tree) {
|
||||||
|
|
||||||
int written = snprintf(tmp + offset, remaining, "%s:", files->items[idx]);
|
int written = snprintf(tmp + offset, remaining, "%s:", files->items[idx]);
|
||||||
if (written < 0 || (size_t)written >= remaining) {
|
if (written < 0 || (size_t)written >= remaining) {
|
||||||
perror("ERROR: buffer overflow in save_tree!\n");
|
perror("ERROR: buffer overflow in snapshot_tree!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +44,7 @@ void save_tree(PathBuffer* tree) {
|
||||||
snprintf(file_path, sizeof(file_path), "%s/%s", dir_path, hash+2);
|
snprintf(file_path, sizeof(file_path), "%s/%s", dir_path, hash+2);
|
||||||
|
|
||||||
FILE* fp = fopen(file_path, "wb");
|
FILE* fp = fopen(file_path, "wb");
|
||||||
if (!fp) { perror("ERROR: cannot open path in save_tree!\n"); return; }
|
if (!fp) { perror("ERROR: cannot open path in snapshot_tree!\n"); return; }
|
||||||
|
|
||||||
|
|
||||||
uLong originalLen = strlen(tmp) + 1;
|
uLong originalLen = strlen(tmp) + 1;
|
||||||
|
|
@ -57,7 +53,7 @@ void save_tree(PathBuffer* tree) {
|
||||||
Bytef compressed[compressedLen];
|
Bytef compressed[compressedLen];
|
||||||
|
|
||||||
if (compress(compressed, &compressedLen, (const Bytef*)tmp, originalLen) != Z_OK) {
|
if (compress(compressed, &compressedLen, (const Bytef*)tmp, originalLen) != Z_OK) {
|
||||||
perror("ERROR: compression failed in save_tree!");
|
perror("ERROR: compression failed in snapshot_tree!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue