Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions s3sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"errors"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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),
Expand Down
Loading