|
40 | 40 | import java.io.FileOutputStream; |
41 | 41 | import java.io.IOException; |
42 | 42 | import java.io.InputStream; |
| 43 | +import java.io.IOError; |
43 | 44 | import java.io.InputStreamReader; |
44 | 45 | import java.io.OutputStream; |
| 46 | +import java.nio.file.InvalidPathException; |
45 | 47 | import java.nio.file.Files; |
46 | 48 | import java.nio.file.Path; |
47 | 49 | import java.nio.file.Paths; |
@@ -273,7 +275,10 @@ else if (arg.equals(include_path_arg)) |
273 | 275 | { |
274 | 276 | if (count < args.length) |
275 | 277 | { |
276 | | - m_includePaths.add(include_path_arg.concat(args[count++])); |
| 278 | + String pathStr = args[count++]; |
| 279 | + if (!isIncludePathDuplicated(pathStr)) { |
| 280 | + m_includePaths.add(include_path_arg.concat(pathStr)); |
| 281 | + } |
277 | 282 | } |
278 | 283 | else |
279 | 284 | { |
@@ -560,8 +565,31 @@ private void showVersion() |
560 | 565 | System.out.println(m_appName + " version " + version); |
561 | 566 | } |
562 | 567 |
|
563 | | - |
564 | | - |
| 568 | + private boolean isIncludePathDuplicated(String pathToCheck) { |
| 569 | + try { |
| 570 | + Path path = Paths.get(pathToCheck); |
| 571 | + String absPath = path.toAbsolutePath().toString(); |
| 572 | + boolean isDuplicateFound = false; |
| 573 | + for (String includePath : m_includePaths) { |
| 574 | + // include paths are prefixed with "-I" |
| 575 | + if (includePath.length() <= 2) { |
| 576 | + continue; |
| 577 | + } |
| 578 | + String absIncludePath = Paths.get(includePath.substring(2)).toAbsolutePath().toString(); |
| 579 | + if (absPath.toLowerCase().equals(absIncludePath.toLowerCase())) { |
| 580 | + isDuplicateFound = true; |
| 581 | + break; |
| 582 | + } |
| 583 | + } |
| 584 | + if (isDuplicateFound) { |
| 585 | + return true; |
| 586 | + } |
| 587 | + } catch (InvalidPathException | IOError | SecurityException ex) { |
| 588 | + // path operations failed, just returning false |
| 589 | + } |
| 590 | + return false; |
| 591 | + } |
| 592 | + |
565 | 593 | /* |
566 | 594 | * ---------------------------------------------------------------------------------------- |
567 | 595 | * Arguments |
|
0 commit comments