mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
Allow to skip the device/get_status call when calling folder_tree_update
- this is useful to safe one extra call when it is known that there should be changes on the remote. In that case it will immediately skip forward to calling device/get_changes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user