Skip to content

Commit 85362cc

Browse files
committed
Update dependency.
1 parent dba2910 commit 85362cc

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

backblaze/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<packaging>jar</packaging>
2626

2727
<properties>
28-
<b2-version>2.1.0</b2-version>
28+
<b2-version>2.2.0</b2-version>
2929
</properties>
3030

3131
<dependencyManagement>

backblaze/src/main/java/ch/cyberduck/core/b2/B2ListService.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,32 @@
2121
import ch.cyberduck.core.Path;
2222
import ch.cyberduck.core.exception.BackgroundException;
2323

24-
import java.util.Collections;
25-
2624
public class B2ListService implements ListService {
2725

2826
private final B2Session session;
2927
private final B2VersionIdProvider fileid;
3028

31-
private Path bucket;
29+
private final AttributedList<Path> buckets;
3230

3331
public B2ListService(final B2Session session, final B2VersionIdProvider fileid) {
32+
this(session, fileid, AttributedList.EMPTY);
33+
}
34+
35+
public B2ListService(final B2Session session, final B2VersionIdProvider fileid, final AttributedList<Path> buckets) {
3436
this.session = session;
3537
this.fileid = fileid;
38+
this.buckets = buckets;
3639
}
3740

3841
@Override
3942
public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
4043
if(directory.isRoot()) {
41-
if(bucket != null) {
42-
final AttributedList<Path> buckets = new AttributedList<>(Collections.singleton(bucket));
43-
listener.chunk(directory, buckets);
44-
return buckets;
44+
if(buckets.isEmpty()) {
45+
return new B2BucketListService(session, fileid).list(directory, listener);
4546
}
46-
return new B2BucketListService(session, fileid).list(directory, listener);
47+
listener.chunk(directory, buckets);
48+
return buckets;
4749
}
4850
return new B2ObjectListService(session, fileid).list(directory, listener);
4951
}
50-
51-
/**
52-
* @param bucket When present, access is restricted to one bucket.
53-
*/
54-
public B2ListService withBucket(final Path bucket) {
55-
this.bucket = bucket;
56-
return this;
57-
}
5852
}

backblaze/src/main/java/ch/cyberduck/core/b2/B2Session.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* GNU General Public License for more details.
1616
*/
1717

18+
import ch.cyberduck.core.AttributedList;
1819
import ch.cyberduck.core.DefaultIOExceptionMappingService;
1920
import ch.cyberduck.core.Host;
2021
import ch.cyberduck.core.HostKeyCallback;
@@ -34,13 +35,13 @@
3435
import ch.cyberduck.core.ssl.X509TrustManager;
3536
import ch.cyberduck.core.threading.CancelCallback;
3637

37-
import org.apache.commons.lang3.StringUtils;
3838
import org.apache.http.impl.client.HttpClientBuilder;
3939
import org.apache.logging.log4j.LogManager;
4040
import org.apache.logging.log4j.Logger;
4141

4242
import java.io.IOException;
4343
import java.util.EnumSet;
44+
import java.util.stream.Collectors;
4445

4546
import synapticloop.b2.B2ApiClient;
4647
import synapticloop.b2.exception.B2ApiException;
@@ -52,7 +53,7 @@ public class B2Session extends HttpSession<B2ApiClient> {
5253
private B2ErrorResponseInterceptor retryHandler;
5354

5455
private final B2VersionIdProvider fileid = new B2VersionIdProvider(this);
55-
private final B2ListService listService = new B2ListService(this, fileid);
56+
private final AttributedList<Path> buckets = new AttributedList<>();
5657

5758
public B2Session(final Host host, final X509TrustManager trust, final X509KeyManager key) {
5859
super(host, trust, key);
@@ -88,10 +89,10 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
8889
// Save tokens for 401 error response when expired
8990
final B2AuthorizeAccountResponse response = client.authenticate(accountId, applicationKey);
9091
// When present, access is restricted to one bucket
91-
if(StringUtils.isNotBlank(response.getBucketId())) {
92-
final PathAttributes attributes = new PathAttributes();
93-
attributes.setVersionId(response.getBucketId());
94-
listService.withBucket(new Path(PathNormalizer.normalize(response.getBucketName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes));
92+
if(!response.getBuckets().isEmpty()) {
93+
buckets.addAll(response.getBuckets().entrySet().stream().map(entry ->
94+
new Path(PathNormalizer.normalize(entry.getValue()), EnumSet.of(Path.Type.directory, Path.Type.volume),
95+
new PathAttributes().setVersionId(entry.getKey()))).collect(Collectors.toSet()));
9596
}
9697
retryHandler.setTokens(accountId, applicationKey, response.getAuthorizationToken());
9798
if(preferences.getBoolean("b2.upload.largeobject.auto")) {
@@ -116,7 +117,7 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
116117
@SuppressWarnings("unchecked")
117118
public <T> T _getFeature(final Class<T> type) {
118119
if(type == ListService.class) {
119-
return (T) listService;
120+
return (T) new B2ListService(this, fileid, buckets);
120121
}
121122
if(type == Touch.class) {
122123
return (T) new B2TouchFeature(this, fileid);

0 commit comments

Comments
 (0)