From 1e15dcc16bdfc27a9d8f277c020c7e6c504bc088 Mon Sep 17 00:00:00 2001 From: josch Date: Tue, 2 Dec 2014 11:04:25 +0100 Subject: [PATCH] fuse: add unlink to remove files --- fuse/main.c | 2 +- fuse/operations.c | 36 ++++++++++++++++++++++++++++++++++++ fuse/operations.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fuse/main.c b/fuse/main.c index 9f2b094..505a13b 100644 --- a/fuse/main.c +++ b/fuse/main.c @@ -63,6 +63,7 @@ static struct fuse_operations mediafirefs_oper = { .open = mediafirefs_open, .read = mediafirefs_read, .release = mediafirefs_release, + .unlink = mediafirefs_unlink, /* .create = mediafirefs_create, .fsync = mediafirefs_fsync, .getxattr = mediafirefs_getxattr, @@ -73,7 +74,6 @@ static struct fuse_operations mediafirefs_oper = { .setxattr = mediafirefs_setxattr, .statfs = mediafirefs_statfs, .truncate = mediafirefs_truncate, - .unlink = mediafirefs_unlink, .utime = mediafirefs_utime, .write = mediafirefs_write,*/ }; diff --git a/fuse/operations.c b/fuse/operations.c index 47ff8ab..76cc68d 100644 --- a/fuse/operations.c +++ b/fuse/operations.c @@ -241,6 +241,42 @@ int mediafirefs_rmdir(const char *path) return 0; } +int mediafirefs_unlink(const char *path) +{ + const char *key; + int retval; + struct mediafirefs_context_private *ctx; + + ctx = fuse_get_context()->private_data; + + /* no need to check + * - if path is directory + * - if directory is empty + * - if directory is root + * + * because getattr was called before and already made sure + */ + + key = folder_tree_path_get_key(ctx->tree, ctx->conn, path); + if (key == NULL) { + fprintf(stderr, "key is NULL\n"); + return -ENOENT; + } + + retval = mfconn_api_file_delete(ctx->conn, key); + mfconn_update_secret_key(ctx->conn); + if (retval != 0) { + fprintf(stderr, "mfconn_api_file_create unsuccessful\n"); + // FIXME: find better errno in this case + return -EAGAIN; + } + + /* retrieve remote changes to not get out of sync */ + folder_tree_update(ctx->tree, ctx->conn); + + return 0; +} + int mediafirefs_open(const char *path, struct fuse_file_info *file_info) { int fd; diff --git a/fuse/operations.h b/fuse/operations.h index 63d941b..e9bcf48 100644 --- a/fuse/operations.h +++ b/fuse/operations.h @@ -40,6 +40,7 @@ int mediafirefs_readdir(const char *path, void *buf, void mediafirefs_destroy(); int mediafirefs_mkdir(const char *path, mode_t mode); int mediafirefs_rmdir(const char *path); +int mediafirefs_unlink(const char *path); int mediafirefs_open(const char *path, struct fuse_file_info *file_info); int mediafirefs_read(const char *path, char *buf, size_t size,