play nice with other implementations that replace " " with "%20"

This commit is contained in:
Lilian Jónsdóttir 2024-06-28 10:45:44 -07:00
parent f9232a095b
commit a3ff94ec8e
3 changed files with 12 additions and 4 deletions

View file

@ -31,5 +31,11 @@ func UnExpand(dir, workdir string) (outdir string) {
outdir = strings.Replace(outdir, home, "~", 1) outdir = strings.Replace(outdir, home, "~", 1)
outdir = UnEscape(outdir)
return return
} }
func UnEscape(input string) string {
return strings.ReplaceAll(input, "%20", " ")
}

View file

@ -88,7 +88,7 @@ func newInfosModel(is trash.Infos, width, height int, readonly, preselected bool
b = humanize.Bytes(uint64(i.Filesize())) b = humanize.Bytes(uint64(i.Filesize()))
} }
r := table.Row{ r := table.Row{
i.Name(), dirs.UnEscape(i.Name()),
dirs.UnExpand(filepath.Dir(i.OGPath()), ""), dirs.UnExpand(filepath.Dir(i.OGPath()), ""),
t, t,
b, b,
@ -149,7 +149,7 @@ func newFilesModel(fs files.Files, width, height int, readonly, preselected bool
b = humanize.Bytes(uint64(f.Filesize())) b = humanize.Bytes(uint64(f.Filesize()))
} }
r := table.Row{ r := table.Row{
f.Name(), dirs.UnEscape(f.Name()),
dirs.UnExpand(f.Path(), workdir), dirs.UnExpand(f.Path(), workdir),
t, t,
b, b,

View file

@ -10,6 +10,7 @@ import (
"strings" "strings"
"time" "time"
"git.burning.moe/celediel/gt/internal/dirs"
"git.burning.moe/celediel/gt/internal/filter" "git.burning.moe/celediel/gt/internal/filter"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
@ -111,8 +112,9 @@ func FindFiles(trashdir, ogdir string, f *filter.Filter) (files Infos, outerr er
func Restore(files []Info) (restored int, err error) { func Restore(files []Info) (restored int, err error) {
for _, file := range files { for _, file := range files {
log.Infof("restoring %s back to %s\n", file.name, file.ogpath) var outpath string = dirs.UnEscape(file.ogpath)
if err = os.Rename(file.path, file.ogpath); err != nil { log.Infof("restoring %s back to %s\n", file.name, outpath)
if err = os.Rename(file.path, outpath); err != nil {
return restored, err return restored, err
} }
if err = os.Remove(file.trashinfo); err != nil { if err = os.Remove(file.trashinfo); err != nil {