forked from cory/tildefriends
I just decided. Braces on their own lines.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3668 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -33,17 +33,22 @@ static void _tf_ssb_import_file_read(uv_fs_t* req)
|
||||
{
|
||||
tf_import_file_t* file = req->data;
|
||||
char id[k_id_base64_len];
|
||||
if (req->result >= 0) {
|
||||
if (tf_ssb_db_blob_store(file->ssb, (const uint8_t*)file->data, req->result, id, sizeof(id))) {
|
||||
if (req->result >= 0)
|
||||
{
|
||||
if (tf_ssb_db_blob_store(file->ssb, (const uint8_t*)file->data, req->result, id, sizeof(id)))
|
||||
{
|
||||
printf("Stored %s/%s as %s.\n", file->parent, file->name, id);
|
||||
if (strcasecmp(file->name + strlen(file->name) - strlen(".json"), ".json") == 0) {
|
||||
if (strcasecmp(file->name + strlen(file->name) - strlen(".json"), ".json") == 0)
|
||||
{
|
||||
sqlite3_stmt* statement;
|
||||
if (sqlite3_prepare(tf_ssb_get_db(file->ssb), "INSERT OR REPLACE INTO properties (id, key, value) VALUES ($1, 'path:' || $2, $3)", -1, &statement, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_prepare(tf_ssb_get_db(file->ssb), "INSERT OR REPLACE INTO properties (id, key, value) VALUES ($1, 'path:' || $2, $3)", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
((char*)file->name)[strlen(file->name) - strlen(".json")] = '\0';
|
||||
if (sqlite3_bind_text(statement, 1, file->user, -1, NULL) == SQLITE_OK &&
|
||||
sqlite3_bind_text(statement, 2, file->name, -1, NULL) == SQLITE_OK &&
|
||||
sqlite3_bind_text(statement, 3, id, -1, NULL) == SQLITE_OK &&
|
||||
sqlite3_step(statement) == SQLITE_DONE) {
|
||||
sqlite3_step(statement) == SQLITE_DONE)
|
||||
{
|
||||
printf("Registered %s path:%s as %s.\n", file->user, file->name, id);
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
@ -75,13 +80,17 @@ static void _tf_ssb_import_scandir(uv_fs_t* req)
|
||||
{
|
||||
tf_import_t* import = req->data;
|
||||
uv_dirent_t ent;
|
||||
while (uv_fs_scandir_next(req, &ent) == 0) {
|
||||
while (uv_fs_scandir_next(req, &ent) == 0)
|
||||
{
|
||||
size_t len = strlen(import->parent) + strlen(ent.name) + 2;
|
||||
char* path = malloc(len);
|
||||
snprintf(path, len, "%s/%s", import->parent, ent.name);
|
||||
if (ent.type == UV_DIRENT_DIR) {
|
||||
if (ent.type == UV_DIRENT_DIR)
|
||||
{
|
||||
tf_ssb_import(import->ssb, import->user, path);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t size = sizeof(tf_import_file_t) + strlen(import->parent) +1 + strlen(ent.name) + 1;
|
||||
tf_import_file_t* file = malloc(size);
|
||||
memset(file, 0, size);
|
||||
@ -96,7 +105,8 @@ static void _tf_ssb_import_scandir(uv_fs_t* req)
|
||||
|
||||
import->work_left++;
|
||||
int r = uv_fs_open(tf_ssb_get_loop(import->ssb), &file->req, path, 0, 0, _tf_ssb_import_file_open);
|
||||
if (r < 0) {
|
||||
if (r < 0)
|
||||
{
|
||||
printf("Failed to open %s: %s.\n", path, uv_strerror(r));
|
||||
free(file);
|
||||
import->work_left--;
|
||||
@ -117,11 +127,13 @@ void tf_ssb_import(tf_ssb_t* ssb, const char* user, const char* path)
|
||||
};
|
||||
import.req.data = &import;
|
||||
int r = uv_fs_scandir(tf_ssb_get_loop(ssb), &import.req, path, 0, _tf_ssb_import_scandir);
|
||||
if (r) {
|
||||
if (r)
|
||||
{
|
||||
printf("Failed to scan directory %s: %s.", path, uv_strerror(r));
|
||||
}
|
||||
|
||||
while (import.work_left > 0) {
|
||||
while (import.work_left > 0)
|
||||
{
|
||||
uv_run(tf_ssb_get_loop(ssb), UV_RUN_ONCE);
|
||||
}
|
||||
uv_fs_req_cleanup(&import.req);
|
||||
|
Reference in New Issue
Block a user