(t *testing.T, mode vfscommon.CacheMode, inCache bool, forceCache bool)
| 299 | } |
| 300 | |
| 301 | func testFileRename(t *testing.T, mode vfscommon.CacheMode, inCache bool, forceCache bool) { |
| 302 | r, vfs, file, item := fileCreate(t, mode) |
| 303 | |
| 304 | if !operations.CanServerSideMove(r.Fremote) { |
| 305 | t.Skip("skip as can't rename files") |
| 306 | } |
| 307 | |
| 308 | rootDir, err := vfs.Root() |
| 309 | require.NoError(t, err) |
| 310 | |
| 311 | // force the file into the cache if required |
| 312 | if forceCache { |
| 313 | // write the file with read and write |
| 314 | fd, err := file.Open(os.O_RDWR | os.O_CREATE | os.O_TRUNC) |
| 315 | require.NoError(t, err) |
| 316 | |
| 317 | n, err := fd.Write([]byte("file1 contents")) |
| 318 | require.NoError(t, err) |
| 319 | require.Equal(t, 14, n) |
| 320 | |
| 321 | require.NoError(t, file.SetModTime(item.ModTime)) |
| 322 | |
| 323 | err = fd.Close() |
| 324 | require.NoError(t, err) |
| 325 | } |
| 326 | vfs.WaitForWriters(waitForWritersDelay) |
| 327 | |
| 328 | // check file in cache |
| 329 | if inCache { |
| 330 | // read contents to get file in cache |
| 331 | fileCheckContents(t, file) |
| 332 | assert.True(t, vfs.cache.Exists(item.Path)) |
| 333 | } |
| 334 | |
| 335 | dir := file.Dir() |
| 336 | |
| 337 | // start with "dir/file1" |
| 338 | r.CheckRemoteItems(t, item) |
| 339 | |
| 340 | // rename file to "newLeaf" |
| 341 | err = dir.Rename("file1", "newLeaf", rootDir) |
| 342 | require.NoError(t, err) |
| 343 | |
| 344 | item.Path = "newLeaf" |
| 345 | r.CheckRemoteItems(t, item) |
| 346 | |
| 347 | // check file in cache |
| 348 | if inCache { |
| 349 | assert.True(t, vfs.cache.Exists(item.Path)) |
| 350 | } |
| 351 | |
| 352 | // check file exists in the vfs layer at its new name |
| 353 | _, err = vfs.Stat("newLeaf") |
| 354 | require.NoError(t, err) |
| 355 | |
| 356 | // rename it back to "dir/file1" |
| 357 | err = rootDir.Rename("newLeaf", "file1", dir) |
| 358 | require.NoError(t, err) |
no test coverage detected
searching dependent graphs…