MCPcopy
hub / github.com/rclone/rclone / testFileSetModTime

Function testFileSetModTime

vfs/file_test.go:91–144  ·  view source on GitHub ↗
(t *testing.T, cacheMode vfscommon.CacheMode, open bool, write bool)

Source from the content-addressed store, hash-verified

89}
90
91func testFileSetModTime(t *testing.T, cacheMode vfscommon.CacheMode, open bool, write bool) {
92 if !canSetModTimeValue {
93 t.Skip("can't set mod time")
94 }
95 r, vfs, file, file1 := fileCreate(t, cacheMode)
96 if !canSetModTime(t, r) {
97 t.Skip("can't set mod time")
98 }
99
100 var (
101 err error
102 fd Handle
103 contents = "file1 contents"
104 )
105 if open {
106 // Open with write intent
107 if cacheMode != vfscommon.CacheModeOff {
108 fd, err = file.Open(os.O_WRONLY)
109 if write {
110 contents = "hello contents"
111 }
112 } else {
113 // Can't write without O_TRUNC with CacheMode Off
114 fd, err = file.Open(os.O_WRONLY | os.O_TRUNC)
115 if write {
116 contents = "hello"
117 } else {
118 contents = ""
119 }
120 }
121 require.NoError(t, err)
122
123 // Write some data
124 if write {
125 _, err = fd.WriteString("hello")
126 require.NoError(t, err)
127 }
128 }
129
130 err = file.SetModTime(t2)
131 require.NoError(t, err)
132
133 if open {
134 require.NoError(t, fd.Close())
135 vfs.WaitForWriters(waitForWritersDelay)
136 }
137
138 file1 = fstest.NewItem(file1.Path, contents, t2)
139 r.CheckRemoteItems(t, file1)
140
141 vfs.Opt.ReadOnly = true
142 err = file.SetModTime(t2)
143 assert.Equal(t, EROFS, err)
144}
145
146// Test various combinations of setting mod times with and
147// without the cache and with and without opening or writing

Callers 1

TestFileSetModTimeFunction · 0.85

Calls 10

NewItemFunction · 0.92
fileCreateFunction · 0.85
canSetModTimeFunction · 0.85
WaitForWritersMethod · 0.80
CheckRemoteItemsMethod · 0.80
OpenMethod · 0.65
WriteStringMethod · 0.65
SetModTimeMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…