|
1 | 1 | package com.upplication.s3fs; |
2 | 2 |
|
3 | | -import com.google.common.base.*; |
4 | | -import com.google.common.collect.ImmutableList; |
5 | | -import com.google.common.collect.Lists; |
6 | | -import com.upplication.s3fs.attribute.S3BasicFileAttributes; |
| 3 | +import static com.google.common.collect.Iterables.concat; |
| 4 | +import static java.lang.String.format; |
7 | 5 |
|
8 | 6 | import java.io.File; |
9 | 7 | import java.io.IOException; |
10 | 8 | import java.io.UnsupportedEncodingException; |
11 | 9 | import java.net.URI; |
12 | 10 | import java.net.URL; |
13 | 11 | import java.net.URLDecoder; |
14 | | -import java.nio.file.*; |
| 12 | +import java.nio.file.LinkOption; |
| 13 | +import java.nio.file.Path; |
| 14 | +import java.nio.file.WatchEvent; |
| 15 | +import java.nio.file.WatchKey; |
| 16 | +import java.nio.file.WatchService; |
15 | 17 | import java.util.Iterator; |
16 | 18 | import java.util.List; |
17 | 19 |
|
18 | | -import static com.google.common.collect.Iterables.*; |
19 | | -import static java.lang.String.format; |
| 20 | +import com.google.common.base.Preconditions; |
| 21 | +import com.google.common.base.Splitter; |
| 22 | +import com.google.common.collect.ImmutableList; |
| 23 | +import com.google.common.collect.Lists; |
| 24 | +import com.upplication.s3fs.attribute.S3BasicFileAttributes; |
20 | 25 |
|
21 | 26 | public class S3Path implements Path { |
22 | 27 |
|
@@ -353,20 +358,30 @@ public Path normalize() { |
353 | 358 |
|
354 | 359 | @Override |
355 | 360 | public Path resolve(Path other) { |
| 361 | + String otherUri = ""; |
356 | 362 | if (other.isAbsolute()) { |
357 | | - Preconditions.checkArgument(other instanceof S3Path, "other must be an instance of %s", S3Path.class.getName()); |
| 363 | + Preconditions.checkArgument(other instanceof S3Path, "other must be an instance of %s or be relative", S3Path.class.getName()); |
358 | 364 | return other; |
| 365 | + } else if (!(other instanceof S3Path)) { |
| 366 | + int nameCount = other.getNameCount(); |
| 367 | + for (int i = 0; i < nameCount; i++) { |
| 368 | + if (i > 0) |
| 369 | + otherUri += PATH_SEPARATOR; |
| 370 | + otherUri += other.getName(i); |
| 371 | + } |
| 372 | + } else { |
| 373 | + S3Path otherS3Path = (S3Path) other; |
| 374 | + otherUri = otherS3Path.uri; |
359 | 375 | } |
360 | 376 |
|
361 | | - S3Path otherS3Path = (S3Path) other; |
362 | 377 | StringBuilder pathBuilder = new StringBuilder(); |
363 | 378 |
|
364 | 379 | if (this.isAbsolute()) { |
365 | 380 | pathBuilder.append(PATH_SEPARATOR + this.fileStore.name() + PATH_SEPARATOR); |
366 | 381 | } |
367 | 382 | pathBuilder.append(this.uri); |
368 | | - if (!otherS3Path.uri.isEmpty()) |
369 | | - pathBuilder.append(PATH_SEPARATOR + otherS3Path.uri); |
| 383 | + if (!otherUri.isEmpty()) |
| 384 | + pathBuilder.append(PATH_SEPARATOR + otherUri); |
370 | 385 |
|
371 | 386 | return new S3Path(this.fileSystem, pathBuilder.toString()); |
372 | 387 | } |
|
0 commit comments