Permalink
Browse files

fixes file path encoding issues

  • Loading branch information...
1 parent 5e921a7 commit 773fad3ffddbd7b83fd13526751391ca99e2c799 @jamessanders committed Feb 1, 2013
Showing with 14 additions and 7 deletions.
  1. +0 −1 java/src/main/java/com/jsync/ResourceCopier.java
  2. +14 −6 java/src/main/java/com/jsync/S3Client.java
View
1 java/src/main/java/com/jsync/ResourceCopier.java
@@ -69,7 +69,6 @@ public static void performDeletions(IResource source, IResource destination, IRe
if (destination.isDirectory()) {
for (IResource resource : destination.list()) {
IResource counterpart = source.join(resource.getName());
- System.out.println(counterpart);
IResource backupTo = null;
if (backup != null) {
backupTo = backup.join(resource.getName());
View
20 java/src/main/java/com/jsync/S3Client.java
@@ -9,6 +9,7 @@
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
@@ -91,31 +92,38 @@ private int getThreadsOpen() {
int c = point;
+ String basepath = null;
+ try {
+ basepath = URLDecoder.decode(uri.getPath(),this.fileEncoding);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
for (S3ObjectSummary object : getObjectList().subList(point, getObjectList().size())) {
String key = "/" + object.getKey();
- String repl = key.replaceFirst("^" + Pattern.quote(uri.getPath()) + "/", "");
- Boolean matches = key.matches("^" + Pattern.quote(uri.getPath()) + "/.*$");
+ String repl = key.replaceFirst("^" + Pattern.quote(basepath) + "/", "");
+ Boolean matches = key.matches("^" + Pattern.quote(basepath) + "/.*$");
- if (key.equals(uri.getPath())) {
+ if (key.equals(basepath)) {
theFile = object;
}
// is subdir
- if (repl.contains("/") && !key.equals(uri.getPath()) && matches) {
+ if (repl.contains("/") && !key.equals(basepath) && matches) {
String name = repl.substring(0, repl.indexOf("/", 1));
if (!visitedSubdirs.contains(name)) {
URIBuilder builder = new URIBuilder();
builder.setScheme("s3");
builder.setHost(bucket);
- builder.setPath(uri.getPath() + "/" + name);
+ builder.setPath(basepath + "/" + name);
subdirs.add(this.getResource(builder.build().toString(), c));
visitedSubdirs.add(name);
}
}
// is file
- else if (!repl.contains("/") && !key.equals(uri.getPath()) && matches) {
+ else if (!repl.contains("/") && !key.equals(basepath) && matches) {
URIBuilder builder = new URIBuilder();
builder.setScheme("s3");
builder.setHost(bucket);

0 comments on commit 773fad3

Please sign in to comment.