diff --git a/s3sync.go b/s3sync.go index 403fb3c..d0be06b 100644 --- a/s3sync.go +++ b/s3sync.go @@ -17,6 +17,7 @@ import ( "errors" "net/url" "os" + "path" "path/filepath" "strings" "sync" @@ -258,8 +259,8 @@ func (m *Manager) syncS3ToLocal(ctx context.Context, chJob chan func(), sourcePa } func (m *Manager) copyS3ToS3(ctx context.Context, file *fileInfo, sourcePath *s3Path, destPath *s3Path) error { - copySource := filepath.ToSlash(filepath.Join(sourcePath.bucket, sourcePath.bucketPrefix, file.name)) - destinationKey := filepath.ToSlash(filepath.Join(destPath.bucketPrefix, file.name)) + copySource := path.Join(sourcePath.bucket, sourcePath.bucketPrefix, file.name) + destinationKey := path.Join(destPath.bucketPrefix, file.name) logf("copy: %s to %s", sourcePath.joinedURL(file.name), destPath.joinedURL(file.name)) @@ -313,8 +314,7 @@ func (m *Manager) download(ctx context.Context, file *fileInfo, sourcePath *s3Pa if file.singleFile { sourceFile = file.name } else { - // Using filepath.ToSlash for change backslash to slash on Windows - sourceFile = filepath.ToSlash(filepath.Join(sourcePath.bucketPrefix, file.name)) + sourceFile = path.Join(sourcePath.bucketPrefix, file.name) } c := manager.NewDownloader(m.s3, m.downloaderOpts...) @@ -366,9 +366,7 @@ func (m *Manager) upload(ctx context.Context, file *fileInfo, sourcePath string, destFile := *destPath if strings.HasSuffix(destPath.bucketPrefix, "/") || destPath.bucketPrefix == "" || !file.singleFile { - // If source is a single file and destination is not a directory, use destination URL as is. - // Using filepath.ToSlash for change backslash to slash on Windows - destFile.bucketPrefix = filepath.ToSlash(filepath.Join(destPath.bucketPrefix, file.name)) + destFile.bucketPrefix = path.Join(destPath.bucketPrefix, file.name) } logf("upload: %s to %s", file.name, destFile.String()) @@ -417,9 +415,7 @@ func (m *Manager) upload(ctx context.Context, file *fileInfo, sourcePath string, func (m *Manager) deleteRemote(ctx context.Context, file *fileInfo, destPath *s3Path) error { destFile := *destPath if strings.HasSuffix(destPath.bucketPrefix, "/") || destPath.bucketPrefix == "" || !file.singleFile { - // If source is a single file and destination is not a directory, use destination URL as is. - // Using filepath.ToSlash for change backslash to slash on Windows - destFile.bucketPrefix = filepath.ToSlash(filepath.Join(destPath.bucketPrefix, file.name)) + destFile.bucketPrefix = path.Join(destPath.bucketPrefix, file.name) } logf("delete: %s", destFile.String()) @@ -473,13 +469,12 @@ func (m *Manager) listS3FileWithToken(ctx context.Context, c chan *fileInfo, pat // Skip directory like object continue } - name, err := filepath.Rel(path.bucketPrefix, *object.Key) - if err != nil { - sendErrorInfoToChannel(ctx, c, err) - continue - } + + name := strings.TrimPrefix(*object.Key, path.bucketPrefix) + name = strings.TrimPrefix(name, "/") + var fi *fileInfo - if name == "." { + if name == "" || name == "." { // Single file was specified fi = &fileInfo{ name: filepath.Base(*object.Key),