MCPcopy Index your code
hub / github.com/devspace-sh/devspace / applyRemoves

Method applyRemoves

pkg/devspace/sync/upstream.go:1010–1071  ·  view source on GitHub ↗
(files []*FileInformation)

Source from the content-addressed store, hash-verified

1008}
1009
1010func (u *upstream) applyRemoves(files []*FileInformation) error {
1011 u.sync.fileIndex.fileMapMutex.Lock()
1012 defer u.sync.fileIndex.fileMapMutex.Unlock()
1013
1014 ctx, cancel := context.WithTimeout(u.sync.ctx, time.Minute*30)
1015 defer cancel()
1016
1017 u.sync.log.Infof("Upstream - Handling %d removes", len(files))
1018 defer u.sync.log.Debugf("Upstream - Done Handling removes")
1019 fileMap := u.sync.fileIndex.fileMap
1020
1021 removeClient, err := u.client.Remove(ctx)
1022 if err != nil {
1023 return errors.Wrap(err, "remove client")
1024 }
1025
1026 sendFiles := make([]string, 0, removeFilesBufferSize)
1027 for _, file := range files {
1028 u.sync.log.Infof("Upstream - Remove '%s'", u.getRelativeUpstreamPath(file.Name))
1029 sendFiles = append(sendFiles, file.Name)
1030
1031 if fileMap[file.Name] != nil {
1032 if fileMap[file.Name].IsDirectory {
1033 u.sync.fileIndex.RemoveDirInFileMap(file.Name)
1034 } else {
1035 delete(fileMap, file.Name)
1036 }
1037
1038 // Print changes
1039 if u.sync.Options.Verbose || len(files) <= 3 {
1040 u.sync.log.Infof("Upstream - Remove '%s'", u.getRelativeUpstreamPath(file.Name))
1041 }
1042 }
1043
1044 if len(sendFiles) >= removeFilesBufferSize {
1045 err = removeClient.Send(&remote.Paths{
1046 Paths: sendFiles,
1047 })
1048 if err != nil {
1049 return errors.Wrap(err, "send paths")
1050 }
1051
1052 sendFiles = make([]string, 0, removeFilesBufferSize)
1053 }
1054 }
1055
1056 if len(sendFiles) > 0 {
1057 err = removeClient.Send(&remote.Paths{
1058 Paths: sendFiles,
1059 })
1060 if err != nil {
1061 return errors.Wrap(err, "send paths")
1062 }
1063 }
1064
1065 _, err = removeClient.CloseAndRecv()
1066 if err != nil {
1067 return errors.Wrap(err, "after deletes")

Callers 1

applyChangesMethod · 0.95

Calls 10

LockMethod · 0.80
UnlockMethod · 0.80
WithTimeoutMethod · 0.80
RemoveDirInFileMapMethod · 0.80
RemoveMethod · 0.65
SendMethod · 0.65
CloseAndRecvMethod · 0.65
InfofMethod · 0.45
DebugfMethod · 0.45

Tested by

no test coverage detected