Skip to content

Commit 91f5ce0

Browse files
authored
Merge pull request #178 from covexo/sync-improvements
Refactoring
2 parents 0809a43 + f65d139 commit 91f5ce0

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

pkg/devspace/sync/sync_config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type SyncConfig struct {
5252

5353
silent bool
5454
stopOnce sync.Once
55+
stopped bool
5556

5657
// Used for testing
5758
testing bool
@@ -88,7 +89,7 @@ func (s *SyncConfig) Error(err error) {
8889
syncLog.WithKey("local", s.WatchPath).WithKey("container", s.DestPath).Errorf("Error: %v, Stack: %v", err, errors.ErrorStack(err))
8990
}
9091

91-
if s.errorChan != nil {
92+
if s.stopped == false && s.errorChan != nil {
9293
s.errorChan <- err
9394
}
9495
}
@@ -372,6 +373,8 @@ func (s *SyncConfig) sendChangesToUpstream(changes []*fileInformation) {
372373
// Stop stops the sync process
373374
func (s *SyncConfig) Stop() {
374375
s.stopOnce.Do(func() {
376+
s.stopped = true
377+
375378
if s.upstream != nil && s.upstream.interrupt != nil {
376379
close(s.upstream.interrupt)
377380

pkg/devspace/sync/upstream.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func (u *upstream) applyCreates(files []*fileInformation) error {
257257
func (u *upstream) uploadArchive(file *os.File, fileSize string, writtenFiles map[string]*fileInformation) error {
258258
u.config.fileIndex.fileMapMutex.Lock()
259259
defer u.config.fileIndex.fileMapMutex.Unlock()
260+
defer file.Close()
260261

261262
u.config.Logf("[Upstream] Upload %d create changes (size %s)", len(writtenFiles), fileSize)
262263

@@ -287,30 +288,26 @@ func (u *upstream) uploadArchive(file *os.File, fileSize string, writtenFiles ma
287288
echo "` + EndAck + `";
288289
` // We need that extra new line or otherwise the command is not sent
289290

290-
if u.stdinPipe != nil {
291-
// Write command
292-
_, err := u.stdinPipe.Write([]byte(cmd))
293-
if err != nil {
294-
return errors.Trace(err)
295-
}
296-
297-
// Wait till confirmation
298-
err = waitTill(StartAck, u.stdoutPipe)
299-
if err != nil {
300-
return errors.Trace(err)
301-
}
291+
// Write command
292+
_, err := u.stdinPipe.Write([]byte(cmd))
293+
if err != nil {
294+
return errors.Trace(err)
295+
}
302296

303-
// Send file through stdin to remote
304-
_, err = io.Copy(u.stdinPipe, file)
305-
if err != nil {
306-
return errors.Trace(err)
307-
}
297+
// Wait till confirmation
298+
err = waitTill(StartAck, u.stdoutPipe)
299+
if err != nil {
300+
return errors.Trace(err)
308301
}
309302

310-
file.Close()
303+
// Send file through stdin to remote
304+
_, err = io.Copy(u.stdinPipe, file)
305+
if err != nil {
306+
return errors.Trace(err)
307+
}
311308

312309
// Delete local file
313-
err := os.Remove(file.Name())
310+
err = os.Remove(file.Name())
314311
if err != nil {
315312
return errors.Trace(err)
316313
}

0 commit comments

Comments
 (0)