@Test public void testFileIdCollision() throws Exception { final B2FileidProvider idProvider = new B2FileidProvider(session); final Path bucket = new B2DirectoryFeature(session, idProvider).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final Path path2R = new Path(bucket, "2R", EnumSet.of(Path.Type.directory)); final Path path33 = new Path(bucket, "33", EnumSet.of(Path.Type.directory)); final Directory directoryFeature = new B2DirectoryFeature(session, idProvider); final Path path2RWithId = directoryFeature.mkdir(path2R, null, new TransferStatus()); assertNotNull(path2RWithId.attributes().getVersionId()); final Path path33WithId = directoryFeature.mkdir(path33, null, new TransferStatus()); assertNotNull(path33WithId.attributes().getVersionId()); assertNotEquals(path2RWithId.attributes().getVersionId(), path33WithId.attributes().getVersionId()); final String fileId = idProvider.getFileid(path33, new DisabledListProgressListener()); assertEquals(fileId, path33WithId.attributes().getVersionId()); assertNotEquals(fileId, path2RWithId.attributes().getVersionId()); new B2DeleteFeature(session, idProvider).delete(Arrays.asList(path2RWithId, path33WithId, bucket), new DisabledPasswordCallback(), new Delete.DisabledCallback()); }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } try { if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return set(file, found.attributes().getVersionId()); } } } if(containerService.isContainer(file)) { final B2BucketResponse info = session.getClient().listBucket(file.getName()); return this.set(file, info.getBucketId()); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final B2ListFilesResponse response = session.getClient().listFileNames( this.getFileid(containerService.getContainer(file), listener), containerService.getKey(file), 2); for(B2FileInfoResponse info : response.getFiles()) { if(StringUtils.equals(containerService.getKey(file), info.getFileName())) { return this.set(file, info.getFileId()); } } throw new NotfoundException(file.getAbsolute()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
B2FileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } try { if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return set(file, found.attributes().getVersionId()); } } } if(containerService.isContainer(file)) { final B2BucketResponse info = session.getClient().listBucket(file.getName()); return this.set(file, info.getBucketId()); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final B2ListFilesResponse response = session.getClient().listFileNames( this.getFileid(containerService.getContainer(file), listener), containerService.getKey(file), 2); for(B2FileInfoResponse info : response.getFiles()) { if(StringUtils.equals(containerService.getKey(file), info.getFileName())) { return this.set(file, info.getFileId()); } } throw new NotfoundException(file.getAbsolute()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
B2FileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } try { if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return set(file, found.attributes().getVersionId()); } } } if(containerService.isContainer(file)) { final B2BucketResponse info = session.getClient().listBucket(file.getName()); return this.set(file, info.getBucketId()); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final B2ListFilesResponse response = session.getClient().listFileNames( this.getFileid(containerService.getContainer(file), listener), containerService.getKey(file), 2); for(B2FileInfoResponse info : response.getFiles()) { if(StringUtils.equals(containerService.getKey(file), info.getFileName())) { return this.set(file, info.getFileId()); } } throw new NotfoundException(file.getAbsolute()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2FileidProvider(final B2Session session); }
B2FileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } try { if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return set(file, found.attributes().getVersionId()); } } } if(containerService.isContainer(file)) { final B2BucketResponse info = session.getClient().listBucket(file.getName()); return this.set(file, info.getBucketId()); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final B2ListFilesResponse response = session.getClient().listFileNames( this.getFileid(containerService.getContainer(file), listener), containerService.getKey(file), 2); for(B2FileInfoResponse info : response.getFiles()) { if(StringUtils.equals(containerService.getKey(file), info.getFileName())) { return this.set(file, info.getFileId()); } } throw new NotfoundException(file.getAbsolute()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2FileidProvider(final B2Session session); @Override String getFileid(final Path file, final ListProgressListener listener); @Override B2FileidProvider withCache(final Cache<Path> cache); }
B2FileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } try { if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return set(file, found.attributes().getVersionId()); } } } if(containerService.isContainer(file)) { final B2BucketResponse info = session.getClient().listBucket(file.getName()); return this.set(file, info.getBucketId()); } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new SimplePathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } final B2ListFilesResponse response = session.getClient().listFileNames( this.getFileid(containerService.getContainer(file), listener), containerService.getKey(file), 2); for(B2FileInfoResponse info : response.getFiles()) { if(StringUtils.equals(containerService.getKey(file), info.getFileName())) { return this.set(file, info.getFileId()); } } throw new NotfoundException(file.getAbsolute()); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2FileidProvider(final B2Session session); @Override String getFileid(final Path file, final ListProgressListener listener); @Override B2FileidProvider withCache(final Cache<Path> cache);  }