Skip to content

Commit

Permalink
Add feature flag for read with offset support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Nov 22, 2024
1 parent 685bca9 commit bfc530b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
20 changes: 19 additions & 1 deletion core/src/main/java/ch/cyberduck/core/features/Read.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.InputStream;
import java.text.MessageFormat;
import java.util.EnumSet;

/**
* Read file from server
Expand All @@ -43,7 +44,10 @@ public interface Read {
* @return True if read with offset is supported
*/
default boolean offset(Path file) throws BackgroundException {
return true;
if(this.features(file).contains(Flags.offset)) {
return true;
}
return false;

}

Expand All @@ -53,4 +57,18 @@ default void preflight(final Path file) throws BackgroundException {
file.getName())).withFile(file);
}
}

/**
* @return Supported features
*/
default EnumSet<Flags> features(Path file) {
return EnumSet.of(Flags.offset);
}

/**
* Feature flags
*/
enum Flags {
offset
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.logging.log4j.Logger;

import java.io.InputStream;
import java.util.EnumSet;

import com.dracoon.sdk.crypto.Crypto;
import com.dracoon.sdk.crypto.error.CryptoException;
Expand Down Expand Up @@ -107,7 +108,7 @@ private UserKeyPair getUserKeyPair(final EncryptedFileKey encFileKey) throws Bac
}

@Override
public boolean offset(final Path file) {
return false;
public EnumSet<Flags> features(final Path file) {
return EnumSet.noneOf(Flags.class);
}
}
20 changes: 12 additions & 8 deletions ftp/src/main/java/ch/cyberduck/core/ftp/FTPReadFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,25 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
import java.util.concurrent.atomic.AtomicBoolean;

public class FTPReadFeature implements Read {
private static final Logger log = LogManager.getLogger(FTPReadFeature.class);

private final FTPSession session;
/**
* Server process supports RESTart in STREAM mode
*/
private final boolean rest;

public FTPReadFeature(final FTPSession session) {
this(session, true);
}

public FTPReadFeature(final FTPSession session, final boolean rest) {
this.session = session;
this.rest = rest;
}

@Override
Expand Down Expand Up @@ -70,14 +80,8 @@ public InputStream execute() throws BackgroundException {
}

@Override
public boolean offset(final Path file) throws BackgroundException {
// Where a server process supports RESTart in STREAM mode
try {
return session.getClient().hasFeature("REST", "STREAM");
}
catch(IOException e) {
throw new FTPExceptionMappingService().map("Download {0} failed", e, file);
}
public EnumSet<Flags> features(final Path file) {
return rest ? EnumSet.of(Flags.offset) : EnumSet.noneOf(Flags.class);
}

private final class ReadReplyInputStream extends ProxyInputStream {
Expand Down
4 changes: 3 additions & 1 deletion ftp/src/main/java/ch/cyberduck/core/ftp/FTPSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class FTPSession extends SSLSession<FTPClient> {
private final PreferencesReader preferences
= new HostPreferences(host);

private Read read;
private Timestamp timestamp;
private UnixPermission permission;
private Symlink symlink;
Expand Down Expand Up @@ -263,6 +264,7 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
catch(IOException e) {
log.warn("SYST command failed {}", e.getMessage());
}
read = new FTPReadFeature(this, client.hasFeature("REST", "STREAM"));
listService = new FTPListService(this, system, zone);
if(client.hasFeature(FTPCmd.MFMT.getCommand())) {
timestamp = new FTPMFMTTimestampFeature(this);
Expand Down Expand Up @@ -302,7 +304,7 @@ public <T> T _getFeature(final Class<T> type) {
return (T) new FTPDeleteFeature(this);
}
if(type == Read.class) {
return (T) new FTPReadFeature(this);
return (T) read;
}
if(type == Upload.class) {
return (T) new FTPUploadFeature(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -88,7 +89,7 @@ public InputStream open() throws IOException {
}

@Override
public boolean offset(final Path file) {
return false;
public EnumSet<Flags> features(final Path file) {
return EnumSet.noneOf(Flags.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testRead() throws Exception {
}

@Test
public void testOffsetSupport() {
public void testOffsetSupport() throws Exception {
assertFalse(new SpectraReadFeature(session).offset(null));
}
}

0 comments on commit bfc530b

Please sign in to comment.