Skip to content

Commit

Permalink
Optimize usages by limiting requested type.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Nov 26, 2024
1 parent 8f2274a commit a772d47
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.Share;

import java.util.EnumSet;

public class DefaultShareFeature implements Share {

private final UrlProvider proxy;
Expand All @@ -33,14 +35,14 @@ public DefaultShareFeature(final UrlProvider proxy) {
@Override
public boolean isSupported(final Path file, final Type type) {
if(Type.download == type) {
return !DescriptiveUrl.EMPTY.equals(proxy.toUrl(file).find(DescriptiveUrl.Type.signed));
return !DescriptiveUrl.EMPTY.equals(proxy.toUrl(file, EnumSet.of(DescriptiveUrl.Type.signed)).find(DescriptiveUrl.Type.signed));
}
return false;
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) {
return proxy.toUrl(file).find(DescriptiveUrl.Type.signed);
return proxy.toUrl(file, EnumSet.of(DescriptiveUrl.Type.signed)).find(DescriptiveUrl.Type.signed);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/ch/cyberduck/core/transfer/Transfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -229,10 +230,10 @@ public TransferItem getRoot() {

public DescriptiveUrl getRemote() {
if(this.roots.size() == 1) {
return new DefaultUrlProvider(host).toUrl(this.getRoot().remote).find(DescriptiveUrl.Type.provider);
return new DefaultUrlProvider(host).toUrl(this.getRoot().remote, EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider);
}
else {
return new DefaultUrlProvider(host).toUrl(this.getRoot().remote.getParent()).find(DescriptiveUrl.Type.provider);
return new DefaultUrlProvider(host).toUrl(this.getRoot().remote.getParent(), EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -284,7 +285,8 @@ public void complete(final Path file, final Local local,
icon.remove(local);
}
if(options.quarantine || options.wherefrom) {
final DescriptiveUrlBag provider = session.getFeature(UrlProvider.class).toUrl(file).filter(DescriptiveUrl.Type.provider, DescriptiveUrl.Type.http);
final DescriptiveUrlBag provider = session.getFeature(UrlProvider.class).toUrl(file,
EnumSet.of(DescriptiveUrl.Type.provider)).filter(DescriptiveUrl.Type.provider, DescriptiveUrl.Type.http);
for(DescriptiveUrl url : provider) {
try {
if(options.quarantine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public synchronized Path create(final Session<?> session, final String region, f
if(credentials.isSaved()) {
try {
keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()),
new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword());
new DefaultUrlProvider(bookmark).toUrl(masterkey, EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword());
}
catch(LocalAccessDeniedException e) {
log.error("Failure {} saving credentials for {} in password store", e, bookmark);
Expand Down Expand Up @@ -210,11 +210,11 @@ public synchronized CryptoVault load(final Session<?> session, final PasswordCal
}
final Host bookmark = session.getHost();
String passphrase = keychain.getPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()),
new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl());
new DefaultUrlProvider(bookmark).toUrl(masterkey, EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl());
if(null == passphrase) {
// Legacy
passphrase = keychain.getPassword(String.format("Cryptomator Passphrase %s", bookmark.getHostname()),
new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl());
new DefaultUrlProvider(bookmark).toUrl(masterkey, EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl());
}
return this.unlock(session, prompt, bookmark, passphrase);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public void unlock(final VaultConfig vaultConfig, final String passphrase, final
log.info("Save passphrase for {}", masterkey);
// Save password with hostname and path to masterkey.cryptomator in keychain
keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()),
new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword());
new DefaultUrlProvider(bookmark).toUrl(masterkey, EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword());
}
}
catch(CryptoAuthenticationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ protected static String toServiceName(final Host bookmark, final UserKeyPair.Ver
}

protected static String toAccountName(final Host bookmark) {
return new DefaultUrlProvider(bookmark).toUrl(new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory))).find(DescriptiveUrl.Type.provider).getUrl();
return new DefaultUrlProvider(bookmark).toUrl(new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)),
EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl();
}

public static PlainDataContainer createPlainDataContainer(final byte[] bytes, final int len) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.InputStream;
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.util.EnumSet;

import com.google.api.client.http.HttpHeaders;
import com.google.api.services.drive.Drive;
Expand All @@ -58,7 +59,7 @@ public DriveReadFeature(final DriveSession session, final DriveFileIdProvider fi
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
if(file.isPlaceholder()) {
final DescriptiveUrl link = new DriveUrlProvider().toUrl(file).find(DescriptiveUrl.Type.http);
final DescriptiveUrl link = new DriveUrlProvider().toUrl(file, EnumSet.of(DescriptiveUrl.Type.http)).find(DescriptiveUrl.Type.http);
if(DescriptiveUrl.EMPTY.equals(link)) {
log.warn("Missing web link for file {}", file);
return new NullInputStream(file.attributes().getSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.NullInputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.nuxeo.onedrive.client.Files;
import org.nuxeo.onedrive.client.OneDriveAPIException;
import org.nuxeo.onedrive.client.types.DriveItem;
import org.nuxeo.onedrive.client.types.DriveItemVersion;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.EnumSet;

public class GraphReadFeature implements Read {
private static final Logger log = LogManager.getLogger(GraphReadFeature.class);
Expand All @@ -57,7 +56,7 @@ public GraphReadFeature(final GraphSession session, final GraphFileIdProvider fi
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
if(file.getType().contains(Path.Type.placeholder)) {
final DescriptiveUrl link = new GraphUrlProvider().toUrl(file).find(DescriptiveUrl.Type.http);
final DescriptiveUrl link = new GraphUrlProvider().toUrl(file, EnumSet.of(DescriptiveUrl.Type.http)).find(DescriptiveUrl.Type.http);
if(DescriptiveUrl.EMPTY.equals(link)) {
log.warn("Missing web link for file {}", file);
return new NullInputStream(file.attributes().getSize());
Expand Down
7 changes: 5 additions & 2 deletions tus/src/main/java/ch/cyberduck/core/tus/TusUploadFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -109,7 +110,8 @@ public Void upload(final Path file, final Local local, final BandwidthThrottle t
throw new InteroperabilityException(String.format("No support for %s", Extension.creation));
}
// Create an Upload URL
final HttpPost request = new HttpPost(new DefaultUrlProvider(host).toUrl(file.getParent()).find(DescriptiveUrl.Type.provider).getUrl());
final HttpPost request = new HttpPost(new DefaultUrlProvider(host).toUrl(file.getParent(),
EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl());
request.setHeader(TUS_HEADER_RESUMABLE, TUS_VERSION);
// The Upload-Length header indicates the size of the entire upload in bytes
request.setHeader(TUS_HEADER_UPLOAD_LENGTH, String.valueOf(status.getDestinationlength()));
Expand Down Expand Up @@ -232,7 +234,8 @@ public Long handleResponse(final HttpResponse response) throws HttpResponseExcep
*/
private static String toUploadUrlPropertyKey(final Host host, final Path file, final TransferStatus status) {
return String.format("tus.url.%s%s",
Base64.encodeBase64String(new DefaultUrlProvider(host).toUrl(file).find(DescriptiveUrl.Type.provider).getUrl().getBytes(StandardCharsets.UTF_8)),
Base64.encodeBase64String(new DefaultUrlProvider(host).toUrl(file,
EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl().getBytes(StandardCharsets.UTF_8)),
null == status.getChecksum() ? StringUtils.EMPTY : String.format(":%s", status.getChecksum().base64));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public DAVCopyFeature(final DAVSession session) {
@Override
public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
try {
final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy).find(DescriptiveUrl.Type.provider).getUrl();
final String target = new DefaultUrlProvider(session.getHost()).toUrl(copy,
EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl();
if(status.getLockId() != null && session.getFeature(Lock.class) != null) {
// Indicate that the client has knowledge of that state token
session.getClient().copy(new DAVPathEncoder().encode(source), target, status.isExists(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public DAVMoveFeature(final DAVSession session) {
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
try {
final String target = new DefaultUrlProvider(session.getHost()).toUrl(renamed).find(DescriptiveUrl.Type.provider).getUrl();
final String target = new DefaultUrlProvider(session.getHost()).toUrl(renamed,
EnumSet.of(DescriptiveUrl.Type.provider)).find(DescriptiveUrl.Type.provider).getUrl();
if(status.getLockId() != null && session.getFeature(Lock.class) != null) {
// Indicate that the client has knowledge of that state token
session.getClient().move(new DAVPathEncoder().encode(file), file.isDirectory() ? String.format("%s/", target) : target,
Expand Down

0 comments on commit a772d47

Please sign in to comment.