Skip to content

vfs: shrinking truncate of an uncached file is silently undone on close (--vfs-cache-mode writes/full) #10047

Closed

Description

@Darkflib

Before you start

  • I have searched the forum and the existing issues for this problem.
  • I have tested with the latest beta or stable release and can still reproduce the problem.
  • This is a reproducible bug, not a usage question (questions belong on the forum).

Associated forum post URL

No response

What is the problem you are having with rclone?

Truncating an existing file to a smaller non-zero size through a mount returns
success, and the mount briefly shows the new size, but on close the VFS cache
re-downloads the whole object over the truncated cache file and uploads it at
the original size. No error is reported. Truncate-then-write leaves a mixture
of old and new bytes.

rclone version

rclone v1.75.1 (official .deb, go1.26.8) and v1.76.0-beta.10454.3b9f0a05b
Debian 13.6, kernel 6.12.101, fuse3 3.17.2. Local backend on ext4; also
reproduced against a serve webdav remote.

Operating system

Linux

Which cloud storage system are you using?

local, webdav

Output of rclone config redacted

empty
**see below**

The command you were trying to run

**Steps to reproduce**
    mkdir back mnt cache && touch empty.conf
    printf 'line1\nline2\nline3\n' > back/f            # 18 bytes
    rclone mount back mnt --vfs-cache-mode writes --config empty.conf \
        --cache-dir cache --log-file mount.log -vv --daemon
    truncate -s 5 mnt/f; echo $?                        # 0
    stat -c %s mnt/f                                    # 5
    sleep 10
    stat -c %s back/f mnt/f                             # 18 and 18

**Expected:** back/f is 5 bytes. **Actual:** 18 bytes, original MD5.

A log from the command with the -vv flag

**Log**
    f: Open: flags=O_WRONLY|0x800
    f: Setattr: ... size=5
    f: vfs cache: truncate to size=18
    f: vfs cache: truncate to size=5
    f: close:
    f: ChunkedReader.openRange at 0 length 134217728
    f: vfs cache: queuing for upload in 5s
    f.13fc66f5.partial: size = 18 OK
    f: Copied (replaced existing)

Anything else?

Notes

  • Same result with --vfs-cache-mode full unless the file was read first, in
    which case the truncate is kept.
  • Under minimal, truncate (O_WRONLY) fails with EPERM, but ftruncate on an
    O_RDWR handle is lost the same way.
  • Not affected: truncate to zero, extending, write-then-truncate, files
    created in the same session.

Activity

  1. hippi345 commented on Oct 6, 2026

    @hippi345

    I'd like to take this one if nobody else is working on it.

    My plan is to find why close re-fetches the object over the truncated cache file for an uncached item, make the shrinking truncate stick in --vfs-cache-mode writes and full, and add a VFS test that truncates an uncached file to a smaller non-zero size and checks the size after close and upload. Happy to go a different direction if you'd prefer.

    AI disclosure: I may use AI coding assistants while working on this. In line with CONTRIBUTING, I'll point them at AGENTS.md, and I'll personally review and test anything I submit and take responsibility for it.

  2. ncw commented on Oct 15, 2026

    @ncw
    Member

    I've merged @flcrom fix for this to master now which means it will be in the latest beta in 15-30 minutes and released in v1.76

  3. added a commit that references this issue on Oct 15, 2026
    78be707
  4. added a commit that references this issue on Oct 16, 2026
    73f5c4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions