From 7a2d7c766d3dd9ae5006361b91bb17816fc36dd7 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 17 Sep 2026 15:18:29 +0100 Subject: [PATCH] vfs: fix crash reading the metadata of a file which is being written With --vfs-metadata-extension set, looking up the metadata file of a file which was open for write and not yet uploaded caused a nil pointer panic. Such a file has no object to read the modification time from. Use the modification time of the VFS node instead, which is valid whether or not the file has been uploaded. --- vfs/dir.go | 2 +- vfs/dir_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/vfs/dir.go b/vfs/dir.go index 0d24195bd..243f0d321 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -845,7 +845,7 @@ func (d *Dir) statMetadata(leaf, baseLeaf string) (metaNode Node, err error) { } // Make a memory based file with metadataDump in remote := path.Join(d.path, leaf) - o := object.NewMemoryObject(remote, entry.ModTime(d.vfs.ctx), metadataDump) + o := object.NewMemoryObject(remote, node.ModTime(), metadataDump) f := newFile(d, d.path, o, leaf) // Base the metadata inode number off the real file inode number // to keep it constant diff --git a/vfs/dir_test.go b/vfs/dir_test.go index 3d7ab8cee..559849503 100644 --- a/vfs/dir_test.go +++ b/vfs/dir_test.go @@ -762,4 +762,16 @@ func TestDirMetadataExtension(t *testing.T) { if features.ReadDirMetadata { assert.Equal(t, modTime.Format(time.RFC3339Nano), metadata["mtime"]) } + + // Check metadata for a file being written, which has no object + // yet, exists and is empty + fd, err := vfs.OpenFile("dir/newfile", os.O_WRONLY|os.O_CREATE, 0666) + require.NoError(t, err) + node, err = vfs.Stat("dir/newfile.metadata") + require.NoError(t, err) + require.True(t, node.IsFile()) + blob, err = vfs.ReadFile("dir/newfile.metadata") + require.NoError(t, err) + assert.Equal(t, "{}", string(blob)) + require.NoError(t, fd.Close()) }