Allow importing from a single app .json.
This commit is contained in:
parent
988a807fa4
commit
4edee0f7f6
@ -231,28 +231,35 @@ static void _tf_ssb_import_app_json(tf_ssb_t* ssb, uv_loop_t* loop, JSContext* c
|
|||||||
|
|
||||||
void tf_ssb_import(tf_ssb_t* ssb, const char* user, const char* path)
|
void tf_ssb_import(tf_ssb_t* ssb, const char* user, const char* path)
|
||||||
{
|
{
|
||||||
uv_fs_t req = { 0 };
|
if (strlen(path) > strlen(".json") && strcasecmp(path + strlen(path) - strlen(".json"), ".json") == 0)
|
||||||
int r = uv_fs_scandir(tf_ssb_get_loop(ssb), &req, path, 0, NULL);
|
|
||||||
if (r >= 0)
|
|
||||||
{
|
{
|
||||||
uv_dirent_t ent;
|
_tf_ssb_import_app_json(ssb, tf_ssb_get_loop(ssb), tf_ssb_get_context(ssb), user, path);
|
||||||
while (uv_fs_scandir_next(&req, &ent) == 0)
|
|
||||||
{
|
|
||||||
size_t len = strlen(path) + strlen(ent.name) + 2;
|
|
||||||
char* full_path = tf_malloc(len);
|
|
||||||
snprintf(full_path, len, "%s/%s", path, ent.name);
|
|
||||||
if (strlen(ent.name) > strlen(".json") && strcasecmp(ent.name + strlen(ent.name) - strlen(".json"), ".json") == 0)
|
|
||||||
{
|
|
||||||
_tf_ssb_import_app_json(ssb, tf_ssb_get_loop(ssb), tf_ssb_get_context(ssb), user, full_path);
|
|
||||||
}
|
|
||||||
tf_free(full_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tf_printf("Failed to scan directory %s: %s.", path, uv_strerror(r));
|
uv_fs_t req = { 0 };
|
||||||
|
int r = uv_fs_scandir(tf_ssb_get_loop(ssb), &req, path, 0, NULL);
|
||||||
|
if (r >= 0)
|
||||||
|
{
|
||||||
|
uv_dirent_t ent;
|
||||||
|
while (uv_fs_scandir_next(&req, &ent) == 0)
|
||||||
|
{
|
||||||
|
size_t len = strlen(path) + strlen(ent.name) + 2;
|
||||||
|
char* full_path = tf_malloc(len);
|
||||||
|
snprintf(full_path, len, "%s/%s", path, ent.name);
|
||||||
|
if (strlen(ent.name) > strlen(".json") && strcasecmp(ent.name + strlen(ent.name) - strlen(".json"), ".json") == 0)
|
||||||
|
{
|
||||||
|
_tf_ssb_import_app_json(ssb, tf_ssb_get_loop(ssb), tf_ssb_get_context(ssb), user, full_path);
|
||||||
|
}
|
||||||
|
tf_free(full_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tf_printf("Failed to scan directory %s: %s.", path, uv_strerror(r));
|
||||||
|
}
|
||||||
|
uv_fs_req_cleanup(&req);
|
||||||
}
|
}
|
||||||
uv_fs_req_cleanup(&req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* _tf_ssb_import_read_current_file_from_zip(unzFile zip, size_t* size)
|
static char* _tf_ssb_import_read_current_file_from_zip(unzFile zip, size_t* size)
|
||||||
|
Loading…
Reference in New Issue
Block a user