Skip to content

Commit de27851

Browse files
committed
Check if find command was correctly executed (#326)
1 parent a7f1bae commit de27851

2 files changed

Lines changed: 16 additions & 23 deletions

File tree

pkg/devspace/sync/downstream.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,13 @@ func (d *downstream) mainLoop() error {
101101

102102
for {
103103
removeFiles := d.cloneFileMap()
104-
removeFilesLen := len(removeFiles)
105104

106105
// Check for changes remotely
107106
createFiles, err := d.collectChanges(removeFiles)
108107
if err != nil {
109108
return errors.Trace(err)
110109
}
111110

112-
// There is an issue with collect changes, hence we return an error
113-
if removeFilesLen == len(removeFiles) {
114-
return errors.New("Sync cannot execute find command remotely")
115-
}
116-
117111
amountChanges := len(createFiles) + len(removeFiles)
118112
if lastAmountChanges > 0 && amountChanges == lastAmountChanges {
119113
err = d.applyChanges(createFiles, removeFiles)
@@ -157,6 +151,7 @@ func (d *downstream) cloneFileMap() map[string]*fileInformation {
157151

158152
func (d *downstream) collectChanges(removeFiles map[string]*fileInformation) ([]*fileInformation, error) {
159153
createFiles := make([]*fileInformation, 0, 128)
154+
destPathFound := false
160155

161156
// Write find command to stdin pipe
162157
cmd := getFindCommand(d.config.DestPath)
@@ -189,7 +184,7 @@ func (d *downstream) collectChanges(removeFiles map[string]*fileInformation) ([]
189184
return nil, errors.Trace(err)
190185
}
191186

192-
done, overlap, err = d.parseLines(string(buf), overlap, &createFiles, removeFiles)
187+
done, overlap, err = d.parseLines(string(buf), overlap, &createFiles, removeFiles, &destPathFound)
193188
if err != nil {
194189
if _, ok := err.(parsingError); ok {
195190
time.Sleep(time.Second * 4)
@@ -201,10 +196,14 @@ func (d *downstream) collectChanges(removeFiles map[string]*fileInformation) ([]
201196
}
202197
}
203198

199+
if destPathFound == false {
200+
return nil, errors.New("DestPath not found, find command did not execute correctly")
201+
}
202+
204203
return createFiles, nil
205204
}
206205

207-
func (d *downstream) parseLines(buffer, overlap string, createFiles *[]*fileInformation, removeFiles map[string]*fileInformation) (bool, string, error) {
206+
func (d *downstream) parseLines(buffer, overlap string, createFiles *[]*fileInformation, removeFiles map[string]*fileInformation, destPathFound *bool) (bool, string, error) {
208207
lines := strings.Split(buffer, "\n")
209208

210209
for index, element := range lines {
@@ -229,7 +228,10 @@ func (d *downstream) parseLines(buffer, overlap string, createFiles *[]*fileInfo
229228
msg: "Parsing Error",
230229
}
231230
} else if line != "" {
232-
err := d.evaluateFile(line, createFiles, removeFiles)
231+
destPath, err := d.evaluateFile(line, createFiles, removeFiles)
232+
if destPath {
233+
*destPathFound = destPath
234+
}
233235

234236
if err != nil {
235237
return true, "", errors.Trace(err)
@@ -240,20 +242,20 @@ func (d *downstream) parseLines(buffer, overlap string, createFiles *[]*fileInfo
240242
return false, overlap, nil
241243
}
242244

243-
func (d *downstream) evaluateFile(fileline string, createFiles *[]*fileInformation, removeFiles map[string]*fileInformation) error {
245+
func (d *downstream) evaluateFile(fileline string, createFiles *[]*fileInformation, removeFiles map[string]*fileInformation) (bool, error) {
244246
d.config.fileIndex.fileMapMutex.Lock()
245247
defer d.config.fileIndex.fileMapMutex.Unlock()
246248

247249
fileInformation, err := parseFileInformation(fileline, d.config.DestPath)
248250

249251
// Error parsing line
250252
if err != nil {
251-
return errors.Trace(err)
253+
return false, errors.Trace(err)
252254
}
253255

254256
// No file found
255257
if fileInformation == nil {
256-
return nil
258+
return true, nil
257259
}
258260

259261
// File found don't delete it
@@ -277,7 +279,7 @@ func (d *downstream) evaluateFile(fileline string, createFiles *[]*fileInformati
277279
*createFiles = append(*createFiles, fileInformation)
278280
}
279281

280-
return nil
282+
return false, nil
281283
}
282284

283285
func (d *downstream) applyChanges(createFiles []*fileInformation, removeFiles map[string]*fileInformation) error {

pkg/devspace/sync/file_information.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,48 +56,42 @@ func (p parsingError) Error() string {
5656
}
5757

5858
func getFindCommand(destPath string) string {
59-
return "mkdir -p '" + destPath + "' && find -L '" + destPath + "' -exec stat -c \"%n///%s,%Y,%f,%a,%u,%g\" {} + 2>/dev/null && echo -n \"" + EndAck + "\" || echo \"" + ErrorAck + "\"\n"
59+
return "mkdir -p '" + destPath + "' && find -L '" + destPath + "' -exec stat -c \"%n///%s,%Y,%f,%a,%u,%g\" {} + 2>/dev/null && echo -n \"" + EndAck + "\" || echo -n \"" + ErrorAck + "\"\n"
6060
}
6161

6262
func parseFileInformation(fileline, destPath string) (*fileInformation, error) {
6363
fileinfo := fileInformation{}
6464

6565
t := strings.Split(fileline, "///")
66-
6766
if len(t) != 2 {
6867
return nil, errors.New("[Downstream] Wrong fileline: " + fileline)
6968
}
70-
7169
if len(t[0]) <= len(destPath) {
7270
return nil, nil
7371
}
7472

7573
fileinfo.Name = t[0][len(destPath):]
7674

7775
t = strings.Split(t[1], ",")
78-
7976
if len(t) != 6 {
8077
return nil, errors.New("[Downstream] Wrong fileline: " + fileline)
8178
}
8279

8380
size, err := strconv.Atoi(t[0])
84-
8581
if err != nil {
8682
return nil, errors.Trace(err)
8783
}
8884

8985
fileinfo.Size = int64(size)
9086

9187
mTime, err := strconv.Atoi(t[1])
92-
9388
if err != nil {
9489
return nil, errors.Trace(err)
9590
}
9691

9792
fileinfo.Mtime = int64(mTime)
9893

9994
rawMode, err := strconv.ParseUint(t[2], 16, 32) // Parse hex string into uint64
100-
10195
if err != nil {
10296
return nil, errors.Trace(err)
10397
}
@@ -107,23 +101,20 @@ func parseFileInformation(fileline, destPath string) (*fileInformation, error) {
107101
fileinfo.IsDirectory = (rawMode & IsDirectory) == IsDirectory
108102

109103
mode, err := strconv.ParseInt(t[3], 8, 32)
110-
111104
if err != nil {
112105
return nil, errors.Trace(err)
113106
}
114107

115108
fileinfo.RemoteMode = mode
116109

117110
uid, err := strconv.Atoi(t[4])
118-
119111
if err != nil {
120112
return nil, errors.Trace(err)
121113
}
122114

123115
fileinfo.RemoteUID = uid
124116

125117
gid, err := strconv.Atoi(t[5])
126-
127118
if err != nil {
128119
return nil, errors.Trace(err)
129120
}

0 commit comments

Comments
 (0)