From bf89b662b7e89c87a33c8ae5196ee553b68d15e0 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Fri, 23 Dec 2016 21:09:50 +0100 Subject: [PATCH 1/2] Add some debug information. --- cloudfuse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudfuse.c b/cloudfuse.c index eccb833..ada4841 100644 --- a/cloudfuse.c +++ b/cloudfuse.c @@ -486,7 +486,7 @@ static int cfs_rmdir(const char* path) static int cfs_ftruncate(const char* path, off_t size, struct fuse_file_info* info) { - debugf(DBG_LEVEL_NORM, KBLU "cfs_ftruncate(%s)", path); + debugf(DBG_LEVEL_NORM, KBLU "cfs_ftruncate(%s) size=%lu", path, size); file_buffer_size = size; openfile* of = (openfile*)(uintptr_t)info->fh; if (ftruncate(of->fd, size)) @@ -543,7 +543,7 @@ static int cfs_fsync(const char* path, int idunno, struct fuse_file_info* info) static int cfs_truncate(const char* path, off_t size) { - debugf(DBG_LEVEL_NORM, "cfs_truncate(%s)", path); + debugf(DBG_LEVEL_NORM, "cfs_truncate(%s) size=%lu", path, size); cloudfs_object_truncate(path, size); debugf(DBG_LEVEL_NORM, "exit: cfs_truncate(%s)", path); return 0; From d1ebf37c06b028d1ffafd474dfaec817ef50c63c Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Fri, 23 Dec 2016 21:11:19 +0100 Subject: [PATCH 2/2] Properly truncate the file at the new position. This ensures that if the new file is smaller than the previous ne, the proper size is uploaded. Fixes for #101. --- cloudfuse.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cloudfuse.c b/cloudfuse.c index ada4841..1ba588f 100644 --- a/cloudfuse.c +++ b/cloudfuse.c @@ -409,7 +409,13 @@ static int cfs_flush(const char* path, struct fuse_file_info* info) if (of) { - update_dir_cache(path, cloudfs_file_size(of->fd), 0, 0); + // get the actual file size and truncate it. This ensures that if the new file is smaller + // than the previous one, the proper size is uploaded. + struct stat stbuf; + cfs_getattr(path, &stbuf); + update_dir_cache(path, stbuf.st_size, 0, 0); + ftruncate(of->fd, stbuf.st_size); + if (of->flags & O_RDWR || of->flags & O_WRONLY) { FILE* fp = fdopen(dup(of->fd), "r"); @@ -545,6 +551,7 @@ static int cfs_truncate(const char* path, off_t size) { debugf(DBG_LEVEL_NORM, "cfs_truncate(%s) size=%lu", path, size); cloudfs_object_truncate(path, size); + update_dir_cache(path, size, 0, 0); debugf(DBG_LEVEL_NORM, "exit: cfs_truncate(%s)", path); return 0; }