1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

vfs: fix applying modtime for an open Write Handle

The symptom of this was that the time set when the file was open was
lost.  This was causing one of the mount tests to fail too.
This commit is contained in:
Nick Craig-Wood
2018-03-06 20:47:11 +00:00
parent 85e0b87c99
commit 0175332987
3 changed files with 54 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package vfs
import (
"os"
"testing"
"time"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fstest"
@@ -214,3 +215,27 @@ func TestWriteFileHandleRelease(t *testing.T) {
assert.NoError(t, err)
assert.True(t, fh.closed)
}
// tests mod time on open files
func TestWriteFileModTimeWithOpenWriters(t *testing.T) {
r := fstest.NewRun(t)
defer r.Finalise()
vfs, fh := writeHandleCreate(t, r)
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC)
_, err := fh.Write([]byte{104, 105})
require.NoError(t, err)
err = fh.Node().SetModTime(mtime)
require.NoError(t, err)
err = fh.Close()
require.NoError(t, err)
info, err := vfs.Stat("file1")
require.NoError(t, err)
// avoid errors because of timezone differences
assert.Equal(t, info.ModTime().Unix(), mtime.Unix())
}