@Test public void testFindAllPendingInBucket() 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).withCache(cache); final B2StartLargeFileResponse start1Response = session.getClient().startLargeFileUpload( fileid.getFileid(bucket, new DisabledListProgressListener()), file.getName(), null, Collections.emptyMap()); final B2StartLargeFileResponse start2Response = session.getClient().startLargeFileUpload( fileid.getFileid(bucket, new DisabledListProgressListener()), file.getName(), null, Collections.emptyMap()); final List<B2FileInfoResponse> list = new B2LargeUploadPartService(session, fileid).find(file); assertFalse(list.isEmpty()); assertEquals(start2Response.getFileId(), list.get(0).getFileId()); assertEquals(start1Response.getFileId(), list.get(1).getFileId()); session.getClient().cancelLargeFileUpload(start1Response.getFileId()); session.getClient().cancelLargeFileUpload(start2Response.getFileId()); }
public List<B2FileInfoResponse> find(final Path file) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Finding multipart uploads for %s", file)); } try { final List<B2FileInfoResponse> uploads = new ArrayList<B2FileInfoResponse>(); String startFileId = null; do { final B2ListFilesResponse chunk; chunk = session.getClient().listUnfinishedLargeFiles( fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), startFileId, null); for(B2FileInfoResponse upload : chunk.getFiles()) { if(file.isDirectory()) { final Path parent = new Path(containerService.getContainer(file), upload.getFileName(), EnumSet.of(Path.Type.file)).getParent(); if(parent.equals(file)) { uploads.add(upload); } } else { if(StringUtils.equals(upload.getFileName(), containerService.getKey(file))) { uploads.add(upload); } } } if(log.isInfoEnabled()) { log.info(String.format("Found %d previous multipart uploads for %s", uploads.size(), file)); } startFileId = chunk.getNextFileId(); } while(startFileId != null); if(log.isInfoEnabled()) { for(B2FileInfoResponse upload : uploads) { log.info(String.format("Found multipart upload %s for %s", upload, file)); } } uploads.sort(new Comparator<B2FileInfoResponse>() { @Override public int compare(final B2FileInfoResponse o1, final B2FileInfoResponse o2) { return o1.getUploadTimestamp().compareTo(o2.getUploadTimestamp()); } }); Collections.reverse(uploads); return uploads; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file); } }
B2LargeUploadPartService { public List<B2FileInfoResponse> find(final Path file) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Finding multipart uploads for %s", file)); } try { final List<B2FileInfoResponse> uploads = new ArrayList<B2FileInfoResponse>(); String startFileId = null; do { final B2ListFilesResponse chunk; chunk = session.getClient().listUnfinishedLargeFiles( fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), startFileId, null); for(B2FileInfoResponse upload : chunk.getFiles()) { if(file.isDirectory()) { final Path parent = new Path(containerService.getContainer(file), upload.getFileName(), EnumSet.of(Path.Type.file)).getParent(); if(parent.equals(file)) { uploads.add(upload); } } else { if(StringUtils.equals(upload.getFileName(), containerService.getKey(file))) { uploads.add(upload); } } } if(log.isInfoEnabled()) { log.info(String.format("Found %d previous multipart uploads for %s", uploads.size(), file)); } startFileId = chunk.getNextFileId(); } while(startFileId != null); if(log.isInfoEnabled()) { for(B2FileInfoResponse upload : uploads) { log.info(String.format("Found multipart upload %s for %s", upload, file)); } } uploads.sort(new Comparator<B2FileInfoResponse>() { @Override public int compare(final B2FileInfoResponse o1, final B2FileInfoResponse o2) { return o1.getUploadTimestamp().compareTo(o2.getUploadTimestamp()); } }); Collections.reverse(uploads); return uploads; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file); } } }
B2LargeUploadPartService { public List<B2FileInfoResponse> find(final Path file) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Finding multipart uploads for %s", file)); } try { final List<B2FileInfoResponse> uploads = new ArrayList<B2FileInfoResponse>(); String startFileId = null; do { final B2ListFilesResponse chunk; chunk = session.getClient().listUnfinishedLargeFiles( fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), startFileId, null); for(B2FileInfoResponse upload : chunk.getFiles()) { if(file.isDirectory()) { final Path parent = new Path(containerService.getContainer(file), upload.getFileName(), EnumSet.of(Path.Type.file)).getParent(); if(parent.equals(file)) { uploads.add(upload); } } else { if(StringUtils.equals(upload.getFileName(), containerService.getKey(file))) { uploads.add(upload); } } } if(log.isInfoEnabled()) { log.info(String.format("Found %d previous multipart uploads for %s", uploads.size(), file)); } startFileId = chunk.getNextFileId(); } while(startFileId != null); if(log.isInfoEnabled()) { for(B2FileInfoResponse upload : uploads) { log.info(String.format("Found multipart upload %s for %s", upload, file)); } } uploads.sort(new Comparator<B2FileInfoResponse>() { @Override public int compare(final B2FileInfoResponse o1, final B2FileInfoResponse o2) { return o1.getUploadTimestamp().compareTo(o2.getUploadTimestamp()); } }); Collections.reverse(uploads); return uploads; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file); } } B2LargeUploadPartService(final B2Session session, final B2FileidProvider fileid); }
B2LargeUploadPartService { public List<B2FileInfoResponse> find(final Path file) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Finding multipart uploads for %s", file)); } try { final List<B2FileInfoResponse> uploads = new ArrayList<B2FileInfoResponse>(); String startFileId = null; do { final B2ListFilesResponse chunk; chunk = session.getClient().listUnfinishedLargeFiles( fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), startFileId, null); for(B2FileInfoResponse upload : chunk.getFiles()) { if(file.isDirectory()) { final Path parent = new Path(containerService.getContainer(file), upload.getFileName(), EnumSet.of(Path.Type.file)).getParent(); if(parent.equals(file)) { uploads.add(upload); } } else { if(StringUtils.equals(upload.getFileName(), containerService.getKey(file))) { uploads.add(upload); } } } if(log.isInfoEnabled()) { log.info(String.format("Found %d previous multipart uploads for %s", uploads.size(), file)); } startFileId = chunk.getNextFileId(); } while(startFileId != null); if(log.isInfoEnabled()) { for(B2FileInfoResponse upload : uploads) { log.info(String.format("Found multipart upload %s for %s", upload, file)); } } uploads.sort(new Comparator<B2FileInfoResponse>() { @Override public int compare(final B2FileInfoResponse o1, final B2FileInfoResponse o2) { return o1.getUploadTimestamp().compareTo(o2.getUploadTimestamp()); } }); Collections.reverse(uploads); return uploads; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file); } } B2LargeUploadPartService(final B2Session session, final B2FileidProvider fileid); List<B2FileInfoResponse> find(final Path file); List<B2UploadPartResponse> list(final String fileid); void delete(final String id); }
B2LargeUploadPartService { public List<B2FileInfoResponse> find(final Path file) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Finding multipart uploads for %s", file)); } try { final List<B2FileInfoResponse> uploads = new ArrayList<B2FileInfoResponse>(); String startFileId = null; do { final B2ListFilesResponse chunk; chunk = session.getClient().listUnfinishedLargeFiles( fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), startFileId, null); for(B2FileInfoResponse upload : chunk.getFiles()) { if(file.isDirectory()) { final Path parent = new Path(containerService.getContainer(file), upload.getFileName(), EnumSet.of(Path.Type.file)).getParent(); if(parent.equals(file)) { uploads.add(upload); } } else { if(StringUtils.equals(upload.getFileName(), containerService.getKey(file))) { uploads.add(upload); } } } if(log.isInfoEnabled()) { log.info(String.format("Found %d previous multipart uploads for %s", uploads.size(), file)); } startFileId = chunk.getNextFileId(); } while(startFileId != null); if(log.isInfoEnabled()) { for(B2FileInfoResponse upload : uploads) { log.info(String.format("Found multipart upload %s for %s", upload, file)); } } uploads.sort(new Comparator<B2FileInfoResponse>() { @Override public int compare(final B2FileInfoResponse o1, final B2FileInfoResponse o2) { return o1.getUploadTimestamp().compareTo(o2.getUploadTimestamp()); } }); Collections.reverse(uploads); return uploads; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot delete {0}", e, file); } } B2LargeUploadPartService(final B2Session session, final B2FileidProvider fileid); List<B2FileInfoResponse> find(final Path file); List<B2UploadPartResponse> list(final String fileid); void delete(final String id);  }