1515 * GNU General Public License for more details.
1616 */
1717
18+ import ch .cyberduck .core .AttributedList ;
1819import ch .cyberduck .core .DefaultIOExceptionMappingService ;
1920import ch .cyberduck .core .Host ;
2021import ch .cyberduck .core .HostKeyCallback ;
3435import ch .cyberduck .core .ssl .X509TrustManager ;
3536import ch .cyberduck .core .threading .CancelCallback ;
3637
37- import org .apache .commons .lang3 .StringUtils ;
3838import org .apache .http .impl .client .HttpClientBuilder ;
3939import org .apache .logging .log4j .LogManager ;
4040import org .apache .logging .log4j .Logger ;
4141
4242import java .io .IOException ;
4343import java .util .EnumSet ;
44+ import java .util .stream .Collectors ;
4445
4546import synapticloop .b2 .B2ApiClient ;
4647import 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