Command the backend to run a named command The command run is name args may be used to read arguments from opts may be used to read optional arguments from The result should be capable of being JSON encoded If it is a string or a []string it will be shown to the user otherwise it will be JSON enco
(ctx context.Context, name string, arg []string, opt map[string]string)
| 3463 | // If it is a string or a []string it will be shown to the user |
| 3464 | // otherwise it will be JSON encoded and shown to the user like that |
| 3465 | func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[string]string) (out any, err error) { |
| 3466 | switch name { |
| 3467 | case "restore": |
| 3468 | req := s3.RestoreObjectInput{ |
| 3469 | //Bucket: &f.rootBucket, |
| 3470 | //Key: &encodedDirectory, |
| 3471 | RestoreRequest: &types.RestoreRequest{}, |
| 3472 | } |
| 3473 | if lifetime := opt["lifetime"]; lifetime != "" { |
| 3474 | ilifetime, err := strconv.ParseInt(lifetime, 10, 32) |
| 3475 | if err != nil { |
| 3476 | return nil, fmt.Errorf("bad lifetime: %w", err) |
| 3477 | } |
| 3478 | ilifetime32 := int32(ilifetime) |
| 3479 | req.RestoreRequest.Days = &ilifetime32 |
| 3480 | } |
| 3481 | if priority := opt["priority"]; priority != "" { |
| 3482 | req.RestoreRequest.GlacierJobParameters = &types.GlacierJobParameters{ |
| 3483 | Tier: types.Tier(priority), |
| 3484 | } |
| 3485 | } |
| 3486 | if description := opt["description"]; description != "" { |
| 3487 | req.RestoreRequest.Description = &description |
| 3488 | } |
| 3489 | type status struct { |
| 3490 | Status string |
| 3491 | Remote string |
| 3492 | } |
| 3493 | var ( |
| 3494 | outMu sync.Mutex |
| 3495 | out = []status{} |
| 3496 | ) |
| 3497 | err = operations.ListFn(ctx, f, func(obj fs.Object) { |
| 3498 | // Remember this is run --checkers times concurrently |
| 3499 | o, ok := obj.(*Object) |
| 3500 | st := status{Status: "OK", Remote: obj.Remote()} |
| 3501 | defer func() { |
| 3502 | outMu.Lock() |
| 3503 | out = append(out, st) |
| 3504 | outMu.Unlock() |
| 3505 | }() |
| 3506 | if operations.SkipDestructive(ctx, obj, "restore") { |
| 3507 | return |
| 3508 | } |
| 3509 | if !ok { |
| 3510 | st.Status = "Not an S3 object" |
| 3511 | return |
| 3512 | } |
| 3513 | if o.storageClass == nil || (*o.storageClass != "GLACIER" && *o.storageClass != "DEEP_ARCHIVE" && *o.storageClass != "INTELLIGENT_TIERING") { |
| 3514 | st.Status = "Not GLACIER or DEEP_ARCHIVE or INTELLIGENT_TIERING storage class" |
| 3515 | return |
| 3516 | } |
| 3517 | bucket, bucketPath := o.split() |
| 3518 | reqCopy := req |
| 3519 | if *o.storageClass == "INTELLIGENT_TIERING" { |
| 3520 | reqCopy.RestoreRequest.Days = nil |
| 3521 | } |
| 3522 | reqCopy.Bucket = &bucket |
nothing calls this directly
no test coverage detected