@Test public void testFileIdCollision() throws Exception { final Path path2R = new Path("/2R", EnumSet.of(Path.Type.directory)); final Path path33 = new Path("/33", EnumSet.of(Path.Type.directory)); final DriveFileidProvider idProvider = new DriveFileidProvider(session); final Directory directoryFeature = new DriveDirectoryFeature(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 DriveDeleteFeature(session, idProvider).delete(Arrays.asList(path2RWithId, path33WithId), 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(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } DriveFileidProvider(final DriveSession session); }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } DriveFileidProvider(final DriveSession session); @Override String getFileid(final Path file, final ListProgressListener listener); @Override DriveFileidProvider withCache(final Cache<Path> cache); }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } DriveFileidProvider(final DriveSession session); @Override String getFileid(final Path file, final ListProgressListener listener); @Override DriveFileidProvider withCache(final Cache<Path> cache);  }