9
9
"log"
10
10
"net"
11
11
"os"
12
+ "path"
12
13
"path/filepath"
13
14
"sort"
14
15
"strings"
@@ -83,7 +84,7 @@ func (ex *Remote) Upload(ctx context.Context, local, remote string, opts *UpDown
83
84
84
85
remoteFile := remote
85
86
if len (matches ) > 1 { // if there are multiple files, treat remote as a directory
86
- remoteFile = filepath .Join (remote , filepath .Base (match ))
87
+ remoteFile = path .Join (remote , filepath .Base (match ))
87
88
}
88
89
req := sftpReq {
89
90
client : ex .client ,
@@ -132,7 +133,7 @@ func (ex *Remote) Download(ctx context.Context, remote, local string, opts *UpDo
132
133
// if the remote basename does not equal the remoteFile basename,
133
134
// treat remote as a glob pattern and local as a directory
134
135
if filepath .Base (remote ) != filepath .Base (remoteFile ) {
135
- localFile = filepath .Join (local , filepath .Base (remoteFile ))
136
+ localFile = path .Join (local , filepath .Base (remoteFile ))
136
137
}
137
138
138
139
req := sftpReq {
@@ -170,8 +171,8 @@ func (ex *Remote) Sync(ctx context.Context, localDir, remoteDir string, opts *Sy
170
171
171
172
unmatchedFiles , deletedFiles := ex .findUnmatchedFiles (localFiles , remoteFiles , excl )
172
173
for _ , file := range unmatchedFiles {
173
- localPath := filepath .Join (localDir , file )
174
- remotePath := filepath .Join (remoteDir , file )
174
+ localPath := path .Join (localDir , file )
175
+ remotePath := path .Join (remoteDir , file )
175
176
if err = ex .Upload (ctx , localPath , remotePath , & UpDownOpts {Mkdir : true }); err != nil {
176
177
return nil , fmt .Errorf ("failed to upload %s to %s: %w" , localPath , remotePath , err )
177
178
}
@@ -184,7 +185,7 @@ func (ex *Remote) Sync(ctx context.Context, localDir, remoteDir string, opts *Sy
184
185
// note: this may cause attempts to remove files from already deleted directories, but it's ok, Delete is idempotent.
185
186
for _ , file := range deletedFiles {
186
187
deleteOpts := & DeleteOpts {Recursive : remoteFiles [file ].IsDir }
187
- if err = ex .Delete (ctx , filepath .Join (remoteDir , file ), deleteOpts ); err != nil {
188
+ if err = ex .Delete (ctx , path .Join (remoteDir , file ), deleteOpts ); err != nil {
188
189
return nil , fmt .Errorf ("failed to delete %s: %w" , file , err )
189
190
}
190
191
}
@@ -232,8 +233,8 @@ func (ex *Remote) Delete(ctx context.Context, remoteFile string, opts *DeleteOpt
232
233
continue
233
234
}
234
235
235
- path := walker .Path ()
236
- relPath , e := filepath .Rel (remoteFile , path )
236
+ p := walker .Path ()
237
+ relPath , e := filepath .Rel (remoteFile , p )
237
238
if e != nil {
238
239
return e
239
240
}
@@ -268,20 +269,20 @@ func (ex *Remote) Delete(ctx context.Context, remoteFile string, opts *DeleteOpt
268
269
default :
269
270
}
270
271
271
- path := pathsToDelete [i ]
272
- fi , stErr := sftpClient .Stat (path )
272
+ p := pathsToDelete [i ]
273
+ fi , stErr := sftpClient .Stat (p )
273
274
if stErr != nil {
274
- return fmt .Errorf ("failed to stat %s: %w" , path , stErr )
275
+ return fmt .Errorf ("failed to stat %s: %w" , p , stErr )
275
276
}
276
277
277
278
if fi .IsDir () {
278
- err = sftpClient .RemoveDirectory (path )
279
+ err = sftpClient .RemoveDirectory (p )
279
280
} else {
280
- err = sftpClient .Remove (path )
281
+ err = sftpClient .Remove (p )
281
282
}
282
283
283
284
if err != nil {
284
- return fmt .Errorf ("failed to delete %s: %w" , path , err )
285
+ return fmt .Errorf ("failed to delete %s: %w" , p , err )
285
286
}
286
287
}
287
288
@@ -563,7 +564,7 @@ func (ex *Remote) getRemoteFilesProperties(ctx context.Context, dir string, excl
563
564
}
564
565
565
566
for _ , entry := range entries {
566
- fullPath := filepath .Join (dir , entry .Name ())
567
+ fullPath := path .Join (dir , entry .Name ())
567
568
relPath , err := filepath .Rel (root , fullPath )
568
569
if err != nil {
569
570
log .Printf ("[WARN] failed to get relative path for %s: %v" , fullPath , err )
0 commit comments