diff --git a/cmd/acp/main.go b/cmd/acp/main.go index 23cf796..0d8f579 100644 --- a/cmd/acp/main.go +++ b/cmd/acp/main.go @@ -73,8 +73,8 @@ func main() { } for _, s := range r.NoSpaceSources { - logrus.Infof("restore unfinished: base= '%s' relative_path= '%s'", s.Base, s.RelativePath) - opts = append(opts, acp.AccurateSource(s.Base, s.RelativePath)) + logrus.Infof("restore unfinished: base= '%s' relative_path= '%v'", s.Base, s.RelativePaths) + opts = append(opts, acp.AccurateSource(s.Base, s.RelativePaths...)) } } else { opts = append(opts, acp.Source(sources...)) diff --git a/opt.go b/opt.go index 449152f..f9a0996 100644 --- a/opt.go +++ b/opt.go @@ -89,12 +89,7 @@ type Option func(*option) *option func Source(paths ...string) Option { return func(o *option) *option { for _, p := range paths { - p = strings.TrimSpace(p) - if p == "" { - continue - } p = path.Clean(p) - if p[len(p)-1] == '/' { p = p[:len(p)-1] } @@ -108,12 +103,10 @@ func Source(paths ...string) Option { func AccurateSource(base string, relativePaths ...string) Option { return func(o *option) *option { - for _, p := range relativePaths { - p = strings.TrimSpace(p) - if p == "" { - continue - } + base = path.Clean(base) + for _, p := range relativePaths { + p = path.Clean(p) if p[len(p)-1] == '/' { p = p[:len(p)-1] } diff --git a/report.go b/report.go index f259992..b4a1272 100644 --- a/report.go +++ b/report.go @@ -18,7 +18,17 @@ func (c *Copyer) Report() *Report { noSpaceSources := make([]*FilePath, 0, len(nss)) for _, s := range nss { - noSpaceSources = append(noSpaceSources, &FilePath{Base: s.base, RelativePath: s.relativePath}) + if len(noSpaceSources) == 0 { + noSpaceSources = append(noSpaceSources, &FilePath{Base: s.base, RelativePaths: []string{s.relativePath}}) + continue + } + + if last := noSpaceSources[len(noSpaceSources)-1]; last.Base == s.base { + last.RelativePaths = append(last.RelativePaths, s.relativePath) + continue + } + + noSpaceSources = append(noSpaceSources, &FilePath{Base: s.base, RelativePaths: []string{s.relativePath}}) } return &Report{ @@ -73,8 +83,8 @@ type File struct { } type FilePath struct { - Base string `json:"base,omitempty"` - RelativePath string `json:"relative_path,omitempty"` + Base string `json:"base,omitempty"` + RelativePaths []string `json:"relative_paths,omitempty"` } type Report struct {