From e45bd022eb29ae84b9a9e1d84809dc2e1390f6d2 Mon Sep 17 00:00:00 2001 From: sbeimin Date: Mon, 26 Feb 2018 11:31:21 +0100 Subject: [PATCH 1/8] encode relative uri --- src/main/java/com/upplication/s3fs/S3Path.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/upplication/s3fs/S3Path.java b/src/main/java/com/upplication/s3fs/S3Path.java index d3b05e0..e67660e 100644 --- a/src/main/java/com/upplication/s3fs/S3Path.java +++ b/src/main/java/com/upplication/s3fs/S3Path.java @@ -465,7 +465,7 @@ public URI toUri() { return URI.create("s3://" + normalizeURI(builder.toString())); } else { - return URI.create(this.uri); + return URI.create(uri); } } From 842746cc7e8f9823e75803d9206e3fa88124d42c Mon Sep 17 00:00:00 2001 From: sbeimin Date: Mon, 26 Feb 2018 11:39:27 +0100 Subject: [PATCH 2/8] Unit test for relative path with space --- src/test/java/com/upplication/s3fs/Path/ToUriTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java index befcc63..073a921 100644 --- a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java +++ b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java @@ -70,6 +70,9 @@ 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 From e80a8485049cbe01175e34461caf6479daa380f4 Mon Sep 17 00:00:00 2001 From: Tim Wolters Date: Tue, 24 Apr 2018 14:21:55 +0200 Subject: [PATCH 3/8] Parse other Paths to String as long as they are relative --- .../java/com/upplication/s3fs/S3Path.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/upplication/s3fs/S3Path.java b/src/main/java/com/upplication/s3fs/S3Path.java index e67660e..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()); } From 30dcccd2ab65a8d34ed3028a172997fbec302741 Mon Sep 17 00:00:00 2001 From: Tim Wolters Date: Mon, 14 May 2018 10:55:18 +0200 Subject: [PATCH 4/8] Added mandatory unittest for resolve --- .../com/upplication/s3fs/Path/S3PathTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) 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 From da647cdecc5f53bfa7c0d4a96d2cb1cd320ec944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Arn=C3=A1iz?= Date: Wed, 23 May 2018 14:26:07 +0200 Subject: [PATCH 5/8] merge PR #100 fix relative uri encoding in S3Path thx @sbeimin --- .../java/com/upplication/s3fs/Path/ToUriTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/com/upplication/s3fs/Path/ToUriTest.java b/src/test/java/com/upplication/s3fs/Path/ToUriTest.java index 073a921..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"); @@ -75,6 +82,14 @@ public void toUriRelative() { 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 public void toUriBucketWithoutEndSlash() { S3Path s3Path = getPath("/bucket"); From 111614f9d69224321feeef198717cc13494df8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Arn=C3=A1iz?= Date: Wed, 23 May 2018 14:27:38 +0200 Subject: [PATCH 6/8] :tada: bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ebd9073c1954c6d3f17cafb85de6704b16425ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Arn=C3=A1iz?= Date: Wed, 23 May 2018 16:17:58 +0200 Subject: [PATCH 7/8] remove from .travis.yml file to use Travis website environment variables --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) 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: From fc7679409c753cadba995f4b9995a0c223468c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Arn=C3=A1iz?= Date: Wed, 23 May 2018 16:18:06 +0200 Subject: [PATCH 8/8] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ```