MCPcopy
hub / github.com/rclone/rclone / touchFiles

Function touchFiles

cmd/bisync/bisync_test.go:1373–1433  ·  view source on GitHub ↗

touchFiles sets modification time on a group of files. Returns names of touched files and/or error. Note: `rclone touch` can touch only single file, doesn't support filters.

(ctx context.Context, dateStr string, f fs.Fs, dir, glob string)

Source from the content-addressed store, hash-verified

1371// Returns names of touched files and/or error.
1372// Note: `rclone touch` can touch only single file, doesn't support filters.
1373func touchFiles(ctx context.Context, dateStr string, f fs.Fs, dir, glob string) ([]string, error) {
1374 files := []string{}
1375 if f.Precision() == fs.ModTimeNotSupported {
1376 return files, nil
1377 }
1378
1379 date, err := time.ParseInLocation(touchDateFormat, dateStr, bisync.TZ)
1380 if err != nil {
1381 return files, fmt.Errorf("invalid date %q: %w", dateStr, err)
1382 }
1383
1384 matcher, firstErr := filter.GlobPathToRegexp(glob, false)
1385 if firstErr != nil {
1386 return files, fmt.Errorf("invalid glob %q", glob)
1387 }
1388
1389 entries, firstErr := f.List(ctx, "")
1390 if firstErr != nil {
1391 return files, firstErr
1392 }
1393
1394 for _, entry := range entries {
1395 obj, isFile := entry.(fs.Object)
1396 if !isFile {
1397 continue
1398 }
1399 remote := obj.Remote()
1400 if !matcher.MatchString(remote) {
1401 continue
1402 }
1403 files = append(files, dir+remote)
1404
1405 fs.Debugf(obj, "Set modification time %s", dateStr)
1406 err := obj.SetModTime(ctx, date)
1407 if err == fs.ErrorCantSetModTimeWithoutDelete || err == fs.ErrorCantSetModTime {
1408 // Workaround for dropbox, similar to --refresh-times
1409 err = nil
1410 buf := new(bytes.Buffer)
1411 size := obj.Size()
1412 separator := ""
1413 if size > 0 {
1414 filterCtx, fi := filter.AddConfig(ctx)
1415 err = fi.AddFile(remote) // limit Cat to only this file, not all files in dir
1416 if err != nil {
1417 return files, err
1418 }
1419 err = operations.Cat(filterCtx, f, buf, 0, size, []byte(separator))
1420 }
1421 info := object.NewStaticObjectInfo(remote, date, size, true, nil, f)
1422 if err == nil {
1423 _ = obj.Remove(ctx)
1424 _, err = f.Put(ctx, buf, info)
1425 }
1426 }
1427 if firstErr == nil {
1428 firstErr = err
1429 }
1430 }

Callers 1

runTestStepMethod · 0.85

Calls 14

GlobPathToRegexpFunction · 0.92
DebugfFunction · 0.92
AddConfigFunction · 0.92
CatFunction · 0.92
NewStaticObjectInfoFunction · 0.92
AddFileMethod · 0.80
PrecisionMethod · 0.65
ListMethod · 0.65
RemoteMethod · 0.65
SetModTimeMethod · 0.65
SizeMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…