Skip to content

Commit

Permalink
Fix #9973.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jun 12, 2017
1 parent 9799aa2 commit db2e560
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
28 changes: 22 additions & 6 deletions core/src/main/java/ch/cyberduck/core/ProtocolFactory.java
Expand Up @@ -23,6 +23,7 @@
import ch.cyberduck.core.preferences.PreferencesFactory;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import java.util.Arrays;
Expand Down Expand Up @@ -128,14 +129,29 @@ public List<Protocol> find(final Predicate<Protocol> search) {
* @return Matching protocol or null if no match
*/
public Protocol forName(final String identifier) {
return this.forName(this.find(), identifier);
return registered.stream().filter(protocol -> String.valueOf(protocol.hashCode()).equals(identifier)).findFirst().orElse(
this.forName(identifier, null)
);
}

public Protocol forName(final String identifier, final String provider) {
return this.forName(this.find(), identifier, provider);
}

public Protocol forName(final List<Protocol> registered, final String identifier) {
return registered.stream().filter(protocol -> protocol.getProvider().equals(identifier)).findFirst().orElse(
registered.stream().filter(protocol -> String.valueOf(protocol.hashCode()).equals(identifier)).findFirst().orElse(
registered.stream().filter(protocol -> Arrays.asList(protocol.getSchemes()).contains(identifier)).findFirst().orElse(null)
)
public Protocol forName(final List<Protocol> registered, final String identifier, final String provider) {
return registered.stream().filter(protocol -> {
if(StringUtils.equals(protocol.getIdentifier(), identifier)) {
if(null == provider) {
// Matching protocol with no custom provider
return true;
}
else {
return StringUtils.equals(protocol.getProvider(), provider);
}
}
return false;
}).findFirst().orElse(
registered.stream().filter(protocol -> Arrays.asList(protocol.getSchemes()).contains(identifier)).findFirst().orElse(null)
);
}

Expand Down
24 changes: 11 additions & 13 deletions core/src/main/java/ch/cyberduck/core/serializer/HostDictionary.java
Expand Up @@ -63,9 +63,17 @@ public <T> Host deserialize(final T serialized) {
log.warn(String.format("Missing protocol key in %s", serialized));
return null;
}
final Protocol p = protocols.forName(protocolObj.toString());
if(null != p) {
final Host bookmark = new Host(p);
final Protocol protocol;
final String identifier = protocolObj.toString();
final Object providerObj = dict.stringForKey("Provider");
if(providerObj != null) {
protocol = protocols.forName(identifier);
}
else {
protocol = protocols.forName(identifier, providerObj.toString());
}
if(null != protocol) {
final Host bookmark = new Host(protocol);
final Object hostnameObj = dict.stringForKey("Hostname");
if(hostnameObj != null) {
bookmark.setHostname(hostnameObj.toString());
Expand All @@ -74,16 +82,6 @@ public <T> Host deserialize(final T serialized) {
if(uuidObj != null) {
bookmark.setUuid(uuidObj.toString());
}
final Object providerObj = dict.stringForKey("Provider");
if(providerObj != null) {
final Protocol provider = protocols.forName(providerObj.toString());
if(null != provider) {
bookmark.setProtocol(provider);
}
else {
log.warn(String.format("Provider %s no more available. Default to %s", providerObj, bookmark.getProtocol()));
}
}
final Object usernameObj = dict.stringForKey("Username");
if(usernameObj != null) {
bookmark.getCredentials().setUsername(usernameObj.toString());
Expand Down
Expand Up @@ -60,7 +60,7 @@ public Profile deserialize(Object serialized) {
public boolean test(final Protocol protocol) {
return true;
}
}), protocol);
}), protocol, null);
if(null == parent) {
log.error(String.format("Unknown protocol %s in profile", protocol));
return null;
Expand Down

0 comments on commit db2e560

Please sign in to comment.