Skip to content

Commit fc71310

Browse files
committed
Filtering out .state files
1 parent 260d76f commit fc71310

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/cmd/list.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package cmd
1919
import (
2020
"fmt"
2121
"log"
22-
"os"
22+
"os/exec"
2323
"path"
2424
"path/filepath"
2525
"strings"
@@ -43,6 +43,7 @@ retros ls -p=snes Lists all ROM files under snes/
4343
`,
4444
Run: func(cmd *cobra.Command, args []string) {
4545
fmt.Println("ROM files found: ")
46+
fmt.Println()
4647

4748
emulator, err := cmd.Flags().GetString("emulator")
4849

@@ -129,9 +130,10 @@ func listROMFiles(emulator string) (string, error) {
129130
}
130131

131132
func runLs(dirPath string, client *ssh.Client) (string, error) {
133+
lsCmd := "ls " + dirPath + " --ignore=*.state"
134+
132135
if client != nil {
133-
cmd := "ls " + dirPath
134-
output, err := sshutils.ExecuteRemoteCommand(client, cmd)
136+
output, err := sshutils.ExecuteRemoteCommand(client, lsCmd)
135137

136138
if err != nil {
137139
log.Printf("Failed to list ROM files under: %s\n\n", dirPath)
@@ -140,17 +142,13 @@ func runLs(dirPath string, client *ssh.Client) (string, error) {
140142
return output, nil
141143
}
142144

143-
files, err := os.ReadDir(dirPath)
145+
cmd := exec.Command("ls", dirPath, "--ignore=*.state")
146+
147+
out, err := cmd.Output()
144148

145149
if err != nil {
146150
log.Printf("An error occurred when reading %s. Error: %v\n", dirPath, err.Error())
147151
}
148152

149-
var sb strings.Builder
150-
151-
for _, file := range files {
152-
sb.WriteString(file.Name() + "\n")
153-
}
154-
155-
return sb.String(), nil
153+
return string(out), nil
156154
}

0 commit comments

Comments
 (0)