Skip to content

Commit

Permalink
revert quote/unquote method extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelEischer committed Jul 13, 2022
1 parent 782339c commit 9f121f6
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions internal/restic/node.go
Expand Up @@ -340,14 +340,6 @@ func FixTime(t time.Time) time.Time {
}
}

func quote(str string) string {
if str == "" {
return str
}
quoted := strconv.Quote(str)
return quoted[1 : len(quoted)-1]
}

func (node Node) MarshalJSON() ([]byte, error) {
// make sure invalid timestamps for mtime and atime are converted to
// something we can actually save.
Expand All @@ -357,7 +349,8 @@ func (node Node) MarshalJSON() ([]byte, error) {

type nodeJSON Node
nj := nodeJSON(node)
nj.Name = quote(node.Name)
name := strconv.Quote(node.Name)
nj.Name = name[1 : len(name)-1]
if nj.LinkTargetRaw != nil {
panic("LinkTargetRaw must not be set manually")
}
Expand All @@ -369,10 +362,6 @@ func (node Node) MarshalJSON() ([]byte, error) {
return json.Marshal(nj)
}

func unquote(str string) (string, error) {
return strconv.Unquote(`"` + str + `"`)
}

func (node *Node) UnmarshalJSON(data []byte) error {
type nodeJSON Node
nj := (*nodeJSON)(node)
Expand All @@ -382,9 +371,9 @@ func (node *Node) UnmarshalJSON(data []byte) error {
return errors.Wrap(err, "Unmarshal")
}

nj.Name, err = unquote(nj.Name)
nj.Name, err = strconv.Unquote(`"` + nj.Name + `"`)
if err != nil {
return errors.Wrap(err, "UnquoteName")
return errors.Wrap(err, "Unquote")
}
if nj.LinkTargetRaw != nil {
nj.LinkTarget = string(nj.LinkTargetRaw)
Expand Down

0 comments on commit 9f121f6

Please sign in to comment.