diff --git a/fuse/hashtbl.c b/fuse/hashtbl.c index 698206f..cc8a30c 100644 --- a/fuse/hashtbl.c +++ b/fuse/hashtbl.c @@ -1376,8 +1376,12 @@ static int folder_tree_update_folder_info(folder_tree * tree, mfconn * conn, * ask the remote if there are changes after the locally stored revision * * if yes, integrate those changes + * + * the expect_changes parameter allows to skip the call to device/get_status + * because sometimes one knows that there should be a remote change, so it is + * useless to waste time on the additional call */ -void folder_tree_update(folder_tree * tree, mfconn * conn) +void folder_tree_update(folder_tree * tree, mfconn * conn, bool expect_changes) { uint64_t revision_remote; uint64_t i; @@ -1387,12 +1391,14 @@ void folder_tree_update(folder_tree * tree, mfconn * conn) const char *key; uint64_t revision; - mfconn_api_device_get_status(conn, &revision_remote); - mfconn_update_secret_key(conn); + if (!expect_changes) { + mfconn_api_device_get_status(conn, &revision_remote); + mfconn_update_secret_key(conn); - if (tree->revision == revision_remote) { - fprintf(stderr, "Request to update but nothing to do\n"); - return; + if (tree->revision == revision_remote) { + fprintf(stderr, "Request to update but nothing to do\n"); + return; + } } /* @@ -1558,7 +1564,7 @@ int folder_tree_rebuild(folder_tree * tree, mfconn * conn) * call device/get_changes to get possible remote changes while we walked * the tree. */ - folder_tree_update(tree, conn); + folder_tree_update(tree, conn, false); return 0; } diff --git a/fuse/hashtbl.h b/fuse/hashtbl.h index 38df275..0648d57 100644 --- a/fuse/hashtbl.h +++ b/fuse/hashtbl.h @@ -45,7 +45,8 @@ int folder_tree_readdir(folder_tree * tree, mfconn * conn, const char *path, void *buf, fuse_fill_dir_t filldir); -void folder_tree_update(folder_tree * tree, mfconn * conn); +void folder_tree_update(folder_tree * tree, mfconn * conn, + bool expect_changes); int folder_tree_store(folder_tree * tree, FILE * stream); diff --git a/fuse/main.c b/fuse/main.c index b4607e8..e1fb44c 100644 --- a/fuse/main.c +++ b/fuse/main.c @@ -301,7 +301,7 @@ static void connect_mf(struct mediafirefs_user_options *options, fclose(fp); - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, false); } else { // file doesn't exist fprintf(stderr, "creating new hashtable\n"); diff --git a/fuse/operations.c b/fuse/operations.c index 34930a7..c75b9ad 100644 --- a/fuse/operations.c +++ b/fuse/operations.c @@ -113,7 +113,7 @@ int mediafirefs_getattr(const char *path, struct stat *stbuf) size_t i; ctx = fuse_get_context()->private_data; - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, false); retval = folder_tree_getattr(ctx->tree, ctx->conn, path, stbuf); if (retval != 0) { @@ -229,7 +229,7 @@ int mediafirefs_mkdir(const char *path, mode_t mode) free(dirname); - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, true); return 0; } @@ -265,7 +265,7 @@ int mediafirefs_rmdir(const char *path) } /* retrieve remote changes to not get out of sync */ - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, true); return 0; } @@ -301,7 +301,7 @@ int mediafirefs_unlink(const char *path) } /* retrieve remote changes to not get out of sync */ - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, true); return 0; } @@ -467,7 +467,7 @@ int mediafirefs_release(const char *path, struct fuse_file_info *file_info) free(upload_key); - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, true); return 0; } // the file was not opened readonly and also existed on the remote @@ -476,6 +476,6 @@ int mediafirefs_release(const char *path, struct fuse_file_info *file_info) // FIXME: not implemented yet close(openfile->fd); free(openfile); - folder_tree_update(ctx->tree, ctx->conn); + folder_tree_update(ctx->tree, ctx->conn, true); return -ENOSYS; }