(byte[] newResult)
| 578 | * Resolve symbolic links in the parent directories. |
| 579 | */ |
| 580 | private byte[] resolve(byte[] newResult) throws IOException { |
| 581 | int last = 1, nextSize, linkSize; |
| 582 | byte[] linkPath = newResult, bytes; |
| 583 | boolean done, inPlace; |
| 584 | for (int i = 1; i <= newResult.length; i++) { |
| 585 | if (i == newResult.length || newResult[i] == separatorChar) { |
| 586 | done = i >= newResult.length - 1; |
| 587 | // if there is only one segment, do nothing |
| 588 | if (done && linkPath.length == 1) { |
| 589 | return newResult; |
| 590 | } |
| 591 | inPlace = false; |
| 592 | if (linkPath == newResult) { |
| 593 | bytes = newResult; |
| 594 | // if there are no symbolic links, terminate the C string |
| 595 | // instead of copying |
| 596 | if (!done) { |
| 597 | inPlace = true; |
| 598 | newResult[i] = '\0'; |
| 599 | } |
| 600 | } else { |
| 601 | nextSize = i - last + 1; |
| 602 | linkSize = linkPath.length; |
| 603 | if (linkPath[linkSize - 1] == separatorChar) { |
| 604 | linkSize--; |
| 605 | } |
| 606 | bytes = new byte[linkSize + nextSize]; |
| 607 | System.arraycopy(linkPath, 0, bytes, 0, linkSize); |
| 608 | System.arraycopy(newResult, last - 1, bytes, linkSize, |
| 609 | nextSize); |
| 610 | // the full path has already been resolved |
| 611 | } |
| 612 | if (done) { |
| 613 | return bytes; |
| 614 | } |
| 615 | linkPath = resolveLink(bytes, inPlace ? i : bytes.length, true); |
| 616 | if (inPlace) { |
| 617 | newResult[i] = '/'; |
| 618 | } |
| 619 | last = i + 1; |
| 620 | } |
| 621 | } |
| 622 | throw new InternalError(); |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | * Resolve a symbolic link. While the path resolves to an existing path, |
no test coverage detected