Skip to content

Commit 588339c

Browse files
committed
fix: parrallel map access
1 parent ccbe7d1 commit 588339c

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

pckg/uploadcontroller/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ func (uploadController *UploadController) UploadFromConfig(ctx context.Context,
7373
return func(ctx context.Context) (interface{}, error) {
7474
trimmedFilePath := strings.TrimPrefix(path, conf.LocalRootPath)
7575
uploadDestination := fmt.Sprintf("%s/%s", conf.UploadRootPath, trimmedFilePath)
76+
// TODO: add better trim handling in case of name collisions
77+
if conf.LocalRootPath == "." {
78+
uploadDestination = fmt.Sprintf("%s/%s", conf.UploadRootPath, path)
79+
}
7680

7781
return uploadController.uploadFile(ctx, path, uploadDestination)
7882
}

pckg/uploader/ftp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
"os"
99
"path/filepath"
1010
"strings"
11+
"sync"
1112

1213
"github.com/jlaffaye/ftp"
1314
)
1415

1516
type FtpUploader struct {
17+
directoriesMutex sync.RWMutex
1618
PreCreatedDirectories map[string]bool
1719
authConfig config.AuthCredentials
1820
connQueue chan *ftp.ServerConn
@@ -21,6 +23,7 @@ type FtpUploader struct {
2123

2224
func NewFtpUploader(ctx context.Context, authConfig config.AuthCredentials, connectionCount int) (*FtpUploader, error) {
2325
uploader := FtpUploader{
26+
directoriesMutex: sync.RWMutex{},
2427
allConnections: make([]*ftp.ServerConn, 0),
2528
connQueue: make(chan *ftp.ServerConn, connectionCount),
2629
PreCreatedDirectories: make(map[string]bool),
@@ -93,6 +96,9 @@ func (uploader *FtpUploader) createDirectoryIfNotExists(conn *ftp.ServerConn, up
9396
directories := strings.Split(uploadFilePathDir, "/")
9497

9598
for i := range directories {
99+
uploader.directoriesMutex.Lock()
100+
defer uploader.directoriesMutex.Unlock()
101+
96102
remoteDir := filepath.Join(directories[:i+1]...)
97103
if uploader.PreCreatedDirectories[remoteDir] {
98104
continue

0 commit comments

Comments
 (0)