Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download text file prevent "Cannot perform start session: EOF" #290

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions internal/view/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func (v *clusterView) headerPagesParam(c types.Cluster) (items []headerItem) {
// executeCommandConfiguration
ecc := utils.EmptyText
if c.Configuration != nil && c.Configuration.ExecuteCommandConfiguration != nil {
ecc = "On"
ecc = "Exists"
}
// managedStorageConfiguration
msc := utils.EmptyText
if c.Configuration != nil && c.Configuration.ManagedStorageConfiguration != nil {
msc = "On"
msc = "Exists"
}
active, draining, running, pending, activeEC2, activeFargate := 0, 0, 0, 0, 0, 0
for _, statistic := range c.Statistics {
Expand Down
33 changes: 26 additions & 7 deletions internal/view/file.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package view

import (
"bufio"
"bytes"
"fmt"
"io"
Expand Down Expand Up @@ -75,26 +76,44 @@ func (v *view) catFile() (*tview.Form, *string) {
v.app.Notice.Info("Working in progress")
slog.Info("exec", "command", bin+" "+strings.Join(args, " "))

output, err := cmd.Output()
stdout, err := cmd.StdoutPipe()
if err != nil {
v.app.Notice.Errorf("Failed, %s", err.Error())
v.app.Notice.Errorf("Failed to create stdout pipe: %s", err.Error())
return
}

if err := cmd.Start(); err != nil {
v.app.Notice.Errorf("Failed to start command: %s", err.Error())
return
}

scanner := bufio.NewScanner(stdout)
var lines []string
for scanner.Scan() {
line := scanner.Text()
lines = append(lines, line)
}

lines := strings.Split(string(output), "\n")
if err := cmd.Wait(); err != nil {
v.app.Notice.Errorf("Command failed: %s", err.Error())
return
}

if strings.Contains(lines[5], "cat:") {
if len(lines) > 5 && strings.Contains(lines[5], "cat:") {
v.app.Notice.Errorf("Failed cat file \"%s\"", lines[5])
}

content := ""

for _, l := range lines[5:] {
if strings.HasPrefix(l, "Exiting session with sessionId") {
break
}
content += l
content += "\n"
if strings.Contains(l, "Cannot perform start session: EOF") {
break
}
content += l + "\n"
}

var file *os.File
if localPath == "" {
pwd, err := os.Getwd()
Expand Down
2 changes: 1 addition & 1 deletion internal/view/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var hotKeyMap = map[string]keyDescriptionPair{
"s": {key: "s", description: "Toggle running/stopped tasks"},
"w": {key: "w", description: "Describe service events"},
"S": {key: "shift-s", description: "Stop task"},
"P": {key: "shift-p", description: "File transfer"},
"P": {key: "shift-p", description: "Transfer file though a S3 bucket"},
"D": {key: "shift-d", description: "Download text file content(beta)"},
"F": {key: "shift-f", description: "Start port forwarding session"},
"T": {key: "shift-t", description: "Terminate port forwarding session"},
Expand Down