44 "bytes"
55 "context"
66 "encoding/json"
7+ "errors"
78 "io"
89 "path/filepath"
910 "strings"
@@ -14,6 +15,7 @@ import (
1415 _ "github.com/rclone/rclone/backend/s3"
1516
1617 "github.com/rclone/rclone/fs"
18+ "github.com/rclone/rclone/fs/operations"
1719 "github.com/rclone/rclone/fs/sync"
1820
1921 "terraform-provider-iterative/task/common"
@@ -99,9 +101,32 @@ func Transfer(ctx context.Context, source, destination string) error {
99101 return err
100102 }
101103
102- if err := sync .CopyDir (ctx , destinationFileSystem , sourceFileSystem , true ); err != nil {
104+ return sync .CopyDir (ctx , destinationFileSystem , sourceFileSystem , true )
105+ }
106+
107+ func Delete (ctx context.Context , destination string ) error {
108+ destinationFileSystem , err := fs .NewFs (ctx , destination )
109+ if err != nil {
103110 return err
104111 }
105112
113+ actions := []func (context.Context ) error {
114+ func (ctx context.Context ) error {
115+ return operations .Delete (ctx , destinationFileSystem )
116+ },
117+ func (ctx context.Context ) error {
118+ return operations .Rmdirs (ctx , destinationFileSystem , "" , true )
119+ },
120+ }
121+
122+ for _ , action := range actions {
123+ if err := action (ctx ); err != nil {
124+ if ! errors .Is (err , fs .ErrorDirNotFound ) && ! strings .Contains (err .Error (), "no such host" ) {
125+ return common .NotFoundError
126+ }
127+ return err
128+ }
129+ }
130+
106131 return nil
107132}
0 commit comments