Handle 404 with file_state_none for pending large file upload.

This commit is contained in:
David Kocher
2019-10-07 16:53:43 +02:00
parent 69c3eec951
commit 6199b025c4
5 changed files with 43 additions and 5 deletions
@@ -52,12 +52,17 @@ public class B2AttributesFinderFeature implements AttributesFinder {
if(file.isRoot()) {
return PathAttributes.EMPTY;
}
if(file.getType().contains(Path.Type.upload)) {
// Pending large file upload
return PathAttributes.EMPTY;
}
try {
final B2FileResponse info = session.getClient().getFileInfo(fileid.getFileid(file, new DisabledListProgressListener()));
return this.toAttributes(info);
}
catch(B2ApiException e) {
if(StringUtils.equals("file_state_none", e.getMessage())) {
// Pending large file upload
return PathAttributes.EMPTY;
}
throw new B2ExceptionMappingService().map("Failure to read attributes of {0}", e, file);
@@ -24,6 +24,8 @@ import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.Copy;
import ch.cyberduck.core.transfer.TransferStatus;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import synapticloop.b2.exception.B2ApiException;
@@ -49,6 +51,10 @@ public class B2CopyFeature implements Copy {
return new Path(target.getParent(), target.getName(), target.getType(), new B2AttributesFinderFeature(session, fileid).toAttributes(response));
}
catch(B2ApiException e) {
if(StringUtils.equals("file_state_none", e.getMessage())) {
// Pending large file upload
return new B2TouchFeature(session, fileid).touch(target, status);
}
throw new B2ExceptionMappingService().map("Cannot copy {0}", e, source);
}
catch(IOException e) {
@@ -58,6 +64,9 @@ public class B2CopyFeature implements Copy {
@Override
public boolean isSupported(final Path source, final Path target) {
if(source.getType().contains(Path.Type.upload)) {
return false;
}
return containerService.getContainer(source).equals(containerService.getContainer(target));
}
@@ -47,7 +47,10 @@ public class B2MoveFeature implements Move {
@Override
public boolean isSupported(final Path source, final Path target) {
return !containerService.isContainer(source);
if(!containerService.isContainer(source)) {
return new B2CopyFeature(session, fileid).isSupported(source, target);
}
return false;
}
@Override
@@ -25,6 +25,9 @@ import ch.cyberduck.core.http.HttpMethodReleaseInputStream;
import ch.cyberduck.core.http.HttpRange;
import ch.cyberduck.core.transfer.TransferStatus;
import org.apache.commons.io.input.NullInputStream;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.io.InputStream;
@@ -44,6 +47,9 @@ public class B2ReadFeature implements Read {
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
if(file.getType().contains(Path.Type.upload)) {
return new NullInputStream(0L);
}
if(status.isAppend()) {
final HttpRange range = HttpRange.withStatus(status);
return session.getClient().downloadFileRangeByIdToStream(
@@ -55,6 +61,10 @@ public class B2ReadFeature implements Read {
return new HttpMethodReleaseInputStream(response.getResponse());
}
catch(B2ApiException e) {
if(StringUtils.equals("file_state_none", e.getMessage())) {
// Pending large file upload
return new NullInputStream(0L);
}
throw new B2ExceptionMappingService().map("Download {0} failed", e, file);
}
catch(IOException e) {
@@ -15,8 +15,12 @@ package ch.cyberduck.core.b2;
* GNU General Public License for more details.
*/
import ch.cyberduck.core.DisabledConnectionCallback;
import ch.cyberduck.core.DisabledListProgressListener;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.PathAttributes;
import ch.cyberduck.core.SimplePathPredicate;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;
import org.junit.Test;
@@ -28,7 +32,7 @@ import java.util.UUID;
import synapticloop.b2.response.B2StartLargeFileResponse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
@Category(IntegrationTest.class)
public class B2AttributesFinderFeatureTest extends AbstractB2Test {
@@ -37,10 +41,17 @@ public class B2AttributesFinderFeatureTest extends AbstractB2Test {
public void testFindLargeUpload() throws Exception {
final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path file = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final B2FileidProvider fileid = new B2FileidProvider(session);
final B2StartLargeFileResponse startResponse = session.getClient().startLargeFileUpload(
new B2FileidProvider(session).withCache(cache).getFileid(bucket, new DisabledListProgressListener()),
file.getName(), null, Collections.emptyMap());
assertNotNull(new B2AttributesFinderFeature(session, new B2FileidProvider(session)).find(file));
fileid.withCache(cache).getFileid(bucket, new DisabledListProgressListener()),
file.getName(), null, Collections.emptyMap());
assertSame(PathAttributes.EMPTY, new B2AttributesFinderFeature(session, fileid).find(file));
final Path found = new B2ObjectListService(session, fileid).list(bucket, new DisabledListProgressListener()).find(
new SimplePathPredicate(file));
assertTrue(found.getType().contains(Path.Type.upload));
new B2ReadFeature(session, fileid).read(file, new TransferStatus(), new DisabledConnectionCallback()).close();
new B2ReadFeature(session, fileid).read(found, new TransferStatus(), new DisabledConnectionCallback()).close();
assertNotNull(fileid.getFileid(file, new DisabledListProgressListener()));
session.getClient().cancelLargeFileUpload(startResponse.getFileId());
}
}