MCPcopy
hub / github.com/rclone/rclone / testFileRename

Function testFileRename

vfs/file_test.go:301–397  ·  view source on GitHub ↗
(t *testing.T, mode vfscommon.CacheMode, inCache bool, forceCache bool)

Source from the content-addressed store, hash-verified

299}
300
301func 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)

Callers 1

TestFileRenameFunction · 0.85

Calls 15

CanServerSideMoveFunction · 0.92
NewItemFunction · 0.92
fileCreateFunction · 0.85
fileCheckContentsFunction · 0.85
WaitForWritersMethod · 0.80
DirMethod · 0.80
CheckRemoteItemsMethod · 0.80
RootMethod · 0.65
OpenMethod · 0.65
WriteMethod · 0.65
SetModTimeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…