@Test public void testCopyToExistingFile() throws Exception { final Path folder = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final DriveFileidProvider fileid = new DriveFileidProvider(session).withCache(cache); new DriveDirectoryFeature(session, fileid).mkdir(folder, null, new TransferStatus()); final Path test = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DriveTouchFeature(session, fileid).touch(test, new TransferStatus()); final Path copy = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DriveTouchFeature(session, fileid).touch(copy, new TransferStatus()); new DriveCopyFeature(session, fileid).copy(test, copy, new TransferStatus().exists(true), new DisabledConnectionCallback()); final Find find = new DefaultFindFeature(session); assertTrue(find.find(test)); assertTrue(find.find(copy)); new DriveDeleteFeature(session, fileid).delete(Arrays.asList(test, copy), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } }
DriveCopyFeature implements Copy { @Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } } }
DriveCopyFeature implements Copy { @Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } } DriveCopyFeature(final DriveSession session, final DriveFileidProvider fileid); }
DriveCopyFeature implements Copy { @Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } } DriveCopyFeature(final DriveSession session, final DriveFileidProvider fileid); @Override Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback); @Override boolean isRecursive(final Path source, final Path target); @Override boolean isSupported(final Path source, final Path target); }
DriveCopyFeature implements Copy { @Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } } DriveCopyFeature(final DriveSession session, final DriveFileidProvider fileid); @Override Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback); @Override boolean isRecursive(final Path source, final Path target); @Override boolean isSupported(final Path source, final Path target);  }