mirror of
https://github.com/rclone/rclone.git
synced 2026-10-09 22:45:26 -04:00
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.
This commit is contained in:
1 parent
ff958c999f
commit
7a2d7c766d
2 files changed
+13
-1
No files matched your search
+1
-1
@@ -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
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
Reference in new issue
Block a user