diff --git a/.travis.yml b/.travis.yml
index db722d9..a379d70 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,12 +6,6 @@ language: java
jdk:
- openjdk7
- oraclejdk8
-env:
- global:
- - secure: "cJdVQLH5yLcMiafZH1BRubHlsd/P8k4IqVToYQBK8GXx47brewSBb1PL+LlRqKiC83N5uFkkF6Md1gASf8twagg2HjJigfUaHZtlZmtVQw1aGAoLcsns0EZny26Gn29q/K+A3FAtydB9jCnJCt3ZKSD6aT/RT7x5v3nm8C7g7iU="
- - secure: "peM3iQKIGKttf76uUs1vSm6L7A0+sk4it0WrhctQ5CWSFuSHl8pZUKhT+3ESkUL7FnNfG8USb/2EdlhwljH8Dg/e09jQ3OwhOPhbX8pgsn2k4SFJ1+IkB6iAcV/o5DlN87CTRcixInInQLXsSIswiUbhaPLI0dE6xJJG93XvSc8="
- - secure: tlMPSRwLNtMX6sAPle28uItIUoWuWet2EDaWZprKPJsY5u/AmjOigDH6dJCwYFi7t1eWeueYeNgzQjKiVGe1kia00WoEaUwPo+P3C1hCjkKSfjLwMxqLR4VvEj/8FDRBoncwryNWWCCxSxEXL6OCGCUqCqy0eye2KaEV9RJCNoA=
- - secure: bXjOngFzBAcI5uiJyxAx2S9rptFK+Sp0Pa0LQKsPz/lFxCPhgJdhHGqEvpkzxAi41jmR/nTFB/F//a7lWUK3QfHQV9zU39T+nA17wjmpds2+1xYNTAea5ow3bBVelBL0MoIs+sNlwQhIFR7daVpTfnVEJNXCipEzJmLrKptWs7E=
before_install:
- sudo sed -i 's/security.provider.9/#security.provider.9/g' $JAVA_HOME/jre/lib/security/java.security
before_script:
diff --git a/README.md b/README.md
index 33ff61d..94a7a02 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ This project provides a first API implementation, little optimized, but "complet
com.upplication
s3fs
- 2.2.1
+ 2.2.2
```
diff --git a/pom.xml b/pom.xml
index 0ae27b4..2b16861 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.upplication
s3fs
jar
- 2.2.1
+ 2.2.2
s3fs
S3 filesystem provider for Java 7
https://github.com/Upplication/Amazon-S3-FileSystem-NIO2
diff --git a/src/main/java/com/upplication/s3fs/S3Path.java b/src/main/java/com/upplication/s3fs/S3Path.java
index d3b05e0..5eb290e 100644
--- a/src/main/java/com/upplication/s3fs/S3Path.java
+++ b/src/main/java/com/upplication/s3fs/S3Path.java
@@ -1,9 +1,7 @@
package com.upplication.s3fs;
-import com.google.common.base.*;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.upplication.s3fs.attribute.S3BasicFileAttributes;
+import static com.google.common.collect.Iterables.concat;
+import static java.lang.String.format;
import java.io.File;
import java.io.IOException;
@@ -11,12 +9,19 @@
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
-import java.nio.file.*;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
import java.util.Iterator;
import java.util.List;
-import static com.google.common.collect.Iterables.*;
-import static java.lang.String.format;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.upplication.s3fs.attribute.S3BasicFileAttributes;
public class S3Path implements Path {
@@ -353,20 +358,30 @@ public Path normalize() {
@Override
public Path resolve(Path other) {
+ String otherUri = "";
if (other.isAbsolute()) {
- Preconditions.checkArgument(other instanceof S3Path, "other must be an instance of %s", S3Path.class.getName());
+ Preconditions.checkArgument(other instanceof S3Path, "other must be an instance of %s or be relative", S3Path.class.getName());
return other;
+ } else if (!(other instanceof S3Path)) {
+ int nameCount = other.getNameCount();
+ for (int i = 0; i < nameCount; i++) {
+ if (i > 0)
+ otherUri += PATH_SEPARATOR;
+ otherUri += other.getName(i);
+ }
+ } else {
+ S3Path otherS3Path = (S3Path) other;
+ otherUri = otherS3Path.uri;
}
- S3Path otherS3Path = (S3Path) other;
StringBuilder pathBuilder = new StringBuilder();
if (this.isAbsolute()) {
pathBuilder.append(PATH_SEPARATOR + this.fileStore.name() + PATH_SEPARATOR);
}
pathBuilder.append(this.uri);
- if (!otherS3Path.uri.isEmpty())
- pathBuilder.append(PATH_SEPARATOR + otherS3Path.uri);
+ if (!otherUri.isEmpty())
+ pathBuilder.append(PATH_SEPARATOR + otherUri);
return new S3Path(this.fileSystem, pathBuilder.toString());
}
@@ -465,7 +480,7 @@ public URI toUri() {
return URI.create("s3://" + normalizeURI(builder.toString()));
}
else {
- return URI.create(this.uri);
+ return URI.create(uri);
}
}
diff --git a/src/test/java/com/upplication/s3fs/Path/S3PathTest.java b/src/test/java/com/upplication/s3fs/Path/S3PathTest.java
index 5ea0e6c..ccccb0a 100644
--- a/src/test/java/com/upplication/s3fs/Path/S3PathTest.java
+++ b/src/test/java/com/upplication/s3fs/Path/S3PathTest.java
@@ -1,5 +1,6 @@
package com.upplication.s3fs.Path;
+import com.upplication.s3fs.AmazonS3Factory;
import com.upplication.s3fs.S3FileSystem;
import com.upplication.s3fs.S3FileSystemProvider;
import com.upplication.s3fs.S3Path;
@@ -9,8 +10,10 @@
import org.junit.Test;
import java.io.IOException;
+import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.nio.file.WatchEvent;
import java.util.HashMap;
@@ -232,4 +235,55 @@ public void registerWatchService() throws IOException {
S3Path path = forPath("/buck/file");
path.register(null, new WatchEvent.Kind>[0], new WatchEvent.Modifier[0]);
}
+ @Test
+ public void testResolve() throws IOException {
+ S3FileSystem fileSystem2 = null;
+ try {
+ HashMap environments = new HashMap<>();
+ environments.put(AmazonS3Factory.ACCESS_KEY, "accesskey");
+ environments.put(AmazonS3Factory.SECRET_KEY, "secretaccesskey");
+
+ fileSystem2 = (S3FileSystem) FileSystems.newFileSystem(URI.create("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket"), environments);
+
+ //good
+ S3Path parent = (S3Path) fileSystem2.provider().getPath(URI.create("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket"));
+ S3Path child = (S3Path) fileSystem2.provider().getPath(URI.create("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit"));
+ S3Path resolved = (S3Path) parent.resolve(child);
+
+ assertEquals(child, resolved);
+
+ resolved = (S3Path) parent.resolve("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit");
+ assertEquals(child, resolved);
+
+ resolved = (S3Path) parent.resolve("rabbit");
+ assertEquals(child, resolved);
+
+ resolved = (S3Path) parent.resolve(Paths.get("rabbit")); //unixPath
+ assertEquals(child, resolved);
+
+ resolved = (S3Path) parent.resolve(Paths.get("./rabbit")); //unixPath
+ assertEquals("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/./rabbit", resolved.toString());
+
+ resolved = (S3Path) parent.resolve(Paths.get("./rabbit in space")); //unixPath
+ assertEquals("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/./rabbit%20in%20space", resolved.toString());
+
+ try {
+ parent.resolve(Paths.get("/tmp"));
+ fail("expect IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ //ignore
+ assertEquals("other must be an instance of com.upplication.s3fs.S3Path or be relative", e.getMessage());
+ }
+
+ //bad
+ S3Path parent2 = fileSystem2.getPath("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket");
+ S3Path child2 = fileSystem2.getPath("s3://accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit");
+ S3Path resolved2 = (S3Path) parent2.resolve(child2);
+ assertEquals("s3:/accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/s3:/accesskey:secretaccesskey@s3.test.amazonaws.com/bucket/rabbit", resolved2.toString());
+
+ } finally {
+ if (fileSystem2 != null)
+ fileSystem2.close();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java
index befcc63..be6c3ed 100644
--- a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java
+++ b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java
@@ -57,6 +57,13 @@ public void toUriWithEndSlash() {
assertEquals(S3_GLOBAL_URI_TEST + "bucket/folder/", s3Path.toUri().toString());
}
+ @Test
+ public void toUriWithSpaces() {
+ S3Path s3Path = getPath("/bucket/with spaces");
+
+ assertEquals(S3_GLOBAL_URI_TEST.resolve("bucket/with%20spaces") , s3Path.toUri());
+ }
+
@Test
public void toUriWithNotEndSlash() {
S3Path s3Path = getPath("/bucket/file");
@@ -70,6 +77,17 @@ public void toUriRelative() {
S3Path path = new S3Path(fileSystem, "bla");
assertEquals(URI.create("bla"), path.toUri());
+
+ S3Path withSpaces = new S3Path(fileSystem, "with space");
+ assertEquals(URI.create("with%20space"), withSpaces.toUri());
+ }
+
+ @Test
+ public void toUriRelativeWithSpaces() {
+ S3FileSystem fileSystem = s3fsProvider.getFileSystem(S3_GLOBAL_URI_TEST);
+
+ S3Path path = new S3Path(fileSystem, "with space");
+ assertEquals(URI.create("with%20space"), path.toUri());
}
@Test