Skip to content

Commit 7217331

Browse files
committed
fail on different dir for same file name
1 parent 0e6ec5a commit 7217331

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cli/parse.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
238238

239239
stringArgs := make([]string, 0, numInputs)
240240
fileArgs := make([]files.DirEntry, 0)
241+
// Each file argument's import directory name is recorded under its base name
242+
// to reject two files with the same name but different import directories
243+
// (same directory just means the _exact_ same file, so we can skip it):
244+
// file base name -> file directory name
245+
fileImportDirName := make(map[string]string)
241246
var fileStdin files.Node
242247

243248
// the index of the current argument definition
@@ -325,6 +330,17 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
325330
}
326331

327332
fpath = filepath.Base(fpath)
333+
importDir := filepath.Dir(fpath)
334+
prevDir, ok := fileImportDirName[fpath]
335+
if !ok {
336+
fileImportDirName[fpath] = importDir
337+
} else {
338+
if prevDir != importDir {
339+
return fmt.Errorf("file name %s repeated under different import directories: %s and %s",
340+
fpath, importDir, prevDir)
341+
}
342+
continue // Skip repeated files.
343+
}
328344
file = nf
329345
}
330346

0 commit comments

Comments
 (0)