passthrough:truncate(): work on file descriptor when possible
authorNikolaus Rath <Nikolaus@rath.org>
Fri, 7 Apr 2017 23:27:59 +0000 (16:27 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Fri, 7 Apr 2017 23:40:15 +0000 (16:40 -0700)
This allows truncating an open file even if write permission
was removed after open() (which is the expected behavior).

example/passthrough.c

index 55f770415a6f7d5332a9ed5bc30fca5106de3062..67663abb76a59e7cd7b66bc21ea7c5db1ff4e7f1 100644 (file)
@@ -250,10 +250,12 @@ static int xmp_chown(const char *path, uid_t uid, gid_t gid,
 static int xmp_truncate(const char *path, off_t size,
                        struct fuse_file_info *fi)
 {
-       (void) fi;
        int res;
 
-       res = truncate(path, size);
+       if (fi != NULL)
+               res = ftruncate(fi->fh, size);
+       else
+               res = truncate(path, size);
        if (res == -1)
                return -errno;