Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit e2a7675

Browse files
author
Tim Wolters
committed
Parse other Paths to String as long as they are relative
1 parent 52d1977 commit e2a7675

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/main/java/com/upplication/s3fs/S3Path.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
package com.upplication.s3fs;
22

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;
75

86
import java.io.File;
97
import java.io.IOException;
108
import java.io.UnsupportedEncodingException;
119
import java.net.URI;
1210
import java.net.URL;
1311
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;
1517
import java.util.Iterator;
1618
import java.util.List;
1719

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;
2025

2126
public class S3Path implements Path {
2227

@@ -353,20 +358,30 @@ public Path normalize() {
353358

354359
@Override
355360
public Path resolve(Path other) {
361+
String otherUri = "";
356362
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());
358364
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;
359375
}
360376

361-
S3Path otherS3Path = (S3Path) other;
362377
StringBuilder pathBuilder = new StringBuilder();
363378

364379
if (this.isAbsolute()) {
365380
pathBuilder.append(PATH_SEPARATOR + this.fileStore.name() + PATH_SEPARATOR);
366381
}
367382
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);
370385

371386
return new S3Path(this.fileSystem, pathBuilder.toString());
372387
}

0 commit comments

Comments
 (0)