9
9
"errors"
10
10
"fmt"
11
11
"path"
12
+ "path/filepath"
12
13
"strings"
13
14
14
15
"golang.org/x/tools/txtar"
@@ -89,6 +90,7 @@ func splitFiles(src []byte) (*fileSet, error) {
89
90
if numFiles > limitNumFiles {
90
91
return nil , fmt .Errorf ("too many files in txtar archive (%v exceeds limit of %v)" , numFiles , limitNumFiles )
91
92
}
93
+ dirFileNameMap := map [string ]string {} // holds which filename the dirname is part of
92
94
for _ , f := range a .Files {
93
95
if len (f .Name ) > 200 { // arbitrary limit
94
96
return nil , errors .New ("file name too long" )
@@ -111,6 +113,16 @@ func splitFiles(src []byte) (*fileSet, error) {
111
113
if fs .Contains (f .Name ) {
112
114
return nil , fmt .Errorf ("duplicate file name %q" , f .Name )
113
115
}
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
+ }
114
126
fs .AddFile (f .Name , f .Data )
115
127
}
116
128
return fs , nil
0 commit comments