99 "errors"
1010 "fmt"
1111 "path"
12+ "path/filepath"
1213 "strings"
1314
1415 "golang.org/x/tools/txtar"
@@ -89,6 +90,7 @@ func splitFiles(src []byte) (*fileSet, error) {
8990 if numFiles > limitNumFiles {
9091 return nil , fmt .Errorf ("too many files in txtar archive (%v exceeds limit of %v)" , numFiles , limitNumFiles )
9192 }
93+ dirFileNameMap := map [string ]string {} // holds which filename the dirname is part of
9294 for _ , f := range a .Files {
9395 if len (f .Name ) > 200 { // arbitrary limit
9496 return nil , errors .New ("file name too long" )
@@ -111,6 +113,16 @@ func splitFiles(src []byte) (*fileSet, error) {
111113 if fs .Contains (f .Name ) {
112114 return nil , fmt .Errorf ("duplicate file name %q" , f .Name )
113115 }
116+ for i := 1 ; i < len (parts ); i ++ {
117+ dirname := filepath .Join (parts [:i ]... )
118+ if fs .Contains (dirname ) {
119+ return nil , fmt .Errorf ("conflict file/dir name %q and %q" , dirname , f .Name )
120+ }
121+ dirFileNameMap [dirname ] = f .Name
122+ }
123+ if filename , ok := dirFileNameMap [f .Name ]; ok {
124+ return nil , fmt .Errorf ("conflict dir/file name %q and %q" , filename , f .Name )
125+ }
114126 fs .AddFile (f .Name , f .Data )
115127 }
116128 return fs , nil
0 commit comments