Skip to content

Commit ea80b0f

Browse files
authored
Merge pull request #52 from leonklingele/remove-file-path-quoting
Remove support for quoting file paths
2 parents 82d7bd3 + 05ee9fe commit ea80b0f

3 files changed

Lines changed: 20 additions & 25 deletions

File tree

godu.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func main() {
5050
}
5151

5252
func printMarkedFiles(lastState *core.State, nullTerminate bool) {
53-
markedFiles := interactive.QuoteMarkedFiles(lastState.MarkedFiles)
53+
markedFiles := interactive.FilesAsSlice(lastState.MarkedFiles)
5454
var printFunc func(string)
5555
if nullTerminate {
5656
printFunc = func(s string) {
@@ -61,8 +61,8 @@ func printMarkedFiles(lastState *core.State, nullTerminate bool) {
6161
fmt.Println(s)
6262
}
6363
}
64-
for _, quotedFile := range markedFiles {
65-
printFunc(quotedFile)
64+
for _, f := range markedFiles {
65+
printFunc(f)
6666
}
6767
}
6868

interactive/printer.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package interactive
22

33
import (
4-
"fmt"
54
"sort"
6-
"strings"
75

86
"github.com/viktomas/godu/core"
97
)
@@ -14,20 +12,16 @@ func (l byLength) Len() int { return len(l) }
1412
func (l byLength) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
1513
func (l byLength) Less(i, j int) bool { return len(l[i]) > len(l[j]) }
1614

17-
// QuoteMarkedFiles takes files from the map and returns slice of qoted file paths
18-
func QuoteMarkedFiles(markedFiles map[*core.File]struct{}) []string {
19-
quotedFiles := make([]string, len(markedFiles))
20-
i := 0
21-
for file := range markedFiles {
15+
// FilesAsSlice takes files from the map and returns a sorted slice of file paths.
16+
func FilesAsSlice(in map[*core.File]struct{}) []string {
17+
out := make([]string, 0, len(in))
18+
for file := range in {
2219
p := file.Path()
23-
// Escape single quotes
24-
p = strings.Replace(p, "'", "\\'", -1)
25-
quotedFiles[i] = fmt.Sprintf("'%s'", p)
26-
i++
20+
out = append(out, p)
2721
}
2822
// sorting lenght of the path (assuming that we want to deleate files in subdirs first)
2923
// alphabetical sorting added for determinism (map keys doesn't guarantee order)
30-
sort.Sort(sort.StringSlice(quotedFiles))
31-
sort.Sort(byLength(quotedFiles))
32-
return quotedFiles
24+
sort.Sort(sort.StringSlice(out))
25+
sort.Sort(byLength(out))
26+
return out
3327
}

interactive/printer_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"github.com/viktomas/godu/core"
88
)
99

10-
func TestPrintEmptyMarkedFiles(t *testing.T) {
10+
func TestFilesAsSliceEmptyMap(t *testing.T) {
1111
marked := make(map[*core.File]struct{})
12-
result := QuoteMarkedFiles(marked)
12+
result := FilesAsSlice(marked)
1313
if len(result) > 0 {
14-
t.Errorf("Expected empty output from PrintMarkedFiles, got '%v'", result)
14+
t.Errorf("Expected empty output, got '%v'", result)
1515
}
1616
}
1717

18-
func TestPrintMarkedFiles(t *testing.T) {
18+
func TestFilesAsSlice(t *testing.T) {
1919
root := core.NewTestFolder(".",
2020
core.NewTestFile("'single''quotes'", 0),
2121
core.NewTestFolder("d1",
@@ -33,9 +33,10 @@ func TestPrintMarkedFiles(t *testing.T) {
3333
marked[core.FindTestFile(root, "f1")] = struct{}{}
3434
marked[core.FindTestFile(root, "f2")] = struct{}{}
3535
marked[core.FindTestFile(root, "'single''quotes'")] = struct{}{}
36-
result := QuoteMarkedFiles(marked)
37-
expected := []string{"'\\'single\\'\\'quotes\\''", "'d1/d3/f2'", "'d1/f1'", "'d1'", "'d2'"}
38-
if !reflect.DeepEqual(result, expected) {
39-
t.Errorf("Expected '%v' from PrintMarkedFiles, got '%v'", expected, result)
36+
37+
want := []string{"'single''quotes'", "d1/d3/f2", "d1/f1", "d1", "d2"}
38+
got := FilesAsSlice(marked)
39+
if !reflect.DeepEqual(want, got) {
40+
t.Errorf("Expected '%v', got '%v'", want, got)
4041
}
4142
}

0 commit comments

Comments
 (0)