public void deleteTest() throws IOException { State state = new State(); setUp(); GoogleDriveFsHelper fsHelper = new GoogleDriveFsHelper(state, client, Closer.create()); Delete delete = mock(Delete.class); String fileId = "test_file_id"; when(files.delete(fileId)).thenReturn(delete); fsHelper.deleteFile(fileId); verify(delete, times(1)).execute(); }
@Override public boolean delete(Path path, boolean recursive) throws IOException { Preconditions.checkArgument(recursive, "Non-recursive is not supported."); String fileId = toFileId(path); LOG.debug("Deleting file: " + fileId); try { client.files().delete(fileId).execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (404 == error.getCode()) { //Non-existing file id return false; } throw e; } return true; }
@Override public boolean delete(Path path, boolean recursive) throws IOException { Preconditions.checkArgument(recursive, "Non-recursive is not supported."); String fileId = toFileId(path); LOG.debug("Deleting file: " + fileId); try { client.files().delete(fileId).execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (404 == error.getCode()) { //Non-existing file id return false; } throw e; } return true; }
final File f = s.getOverview().latestWelcome(welcome); final Spreadsheet result = copySheet(sheetsService, s.getStonky(), f, InternalSheet.WELCOME); driveService.files().delete(f.getId()).execute(); return result; }));
final File f = s.getOverview().latestWelcome(welcome); final Spreadsheet result = copySheet(sheetsService, s.getStonky(), f, InternalSheet.WELCOME); driveService.files().delete(f.getId()).execute(); return result; }));
driveService.files().delete(fileId).execute();
drive.files().delete(existingFiles.getFiles().get(0).getId()).execute();
drive.files().delete(existingFiles.getFiles().get(0).getId()).execute();
private void delete(File file) { Drive drive = driveFactory.getDrive(this.credential); try { String id = file.getId(); if (isGoogleAppsDocument(file)) { LOGGER.log(Level.FINE, String.format("Not deleting file '%s' because it is a Google Apps document.", id)); return; } if (options.isNoDelete()) { LOGGER.log(Level.FINE, String.format("Not deleting file '%s' because option --no-delete is set.", id)); return; } if (options.isDeleteFiles()) { LOGGER.log(Level.FINE, "Deleting file " + id + " (" + file.getName() +")."); if (!options.isDryRun()) { executeWithRetry(options, () -> drive.files().delete(id).execute()); } } else { LOGGER.log(Level.FINE, "Trashing file " + id + " (" + file.getName() +")."); if (!options.isDryRun()) { executeWithRetry(options, () -> drive.files().update("{'trashed':true}", file).execute()); //trash(id).execute()); } } } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to delete file: " + e.getMessage(), e); } }
@Override public void delete(final List<Path> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files) { if(file.getType().contains(Path.Type.placeholder)) { continue; } callback.delete(file); try { if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { session.getClient().teamdrives().delete(fileid.getFileid(file, new DisabledListProgressListener())).execute(); } else { if(PreferencesFactory.get().getBoolean("googledrive.delete.trash")) { final File properties = new File(); properties.setTrashed(true); session.getClient().files().update(fileid.getFileid(file, new DisabledListProgressListener()), properties) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); } else { session.getClient().files().delete(fileid.getFileid(file, new DisabledListProgressListener())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); } } } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot delete {0}", e, file); } } }
/** * @param fileId ID of the fileName to copy * @param destinationFolderId folder ID where to copy the fileId * @param newName if not empty rename copy to this name * @param deleteOriginal remove original fileName (aka mv) * @return copied fileName ID * @throws IOException when copy fails */ public String copyFile(String fileId, String destinationFolderId, String newName, boolean deleteOriginal) throws IOException { LOG.debug("[copyFile] fileId: {}; destinationFolderId: {}, newName: {}; deleteOriginal: {}.", fileId, destinationFolderId, newName, deleteOriginal); File copy = new File(); copy.setParents(Collections.singletonList(destinationFolderId)); if (!newName.isEmpty()) { copy.setName(newName); } File resultFile = drive.files().copy(fileId, copy).setFields("id, parents").execute(); String copiedResourceId = resultFile.getId(); if (deleteOriginal) { drive.files().delete(fileId).execute(); } return copiedResourceId; }
/** * @param fileId ID of the fileName to copy * @param destinationFolderId folder ID where to copy the fileId * @param newName if not empty rename copy to this name * @param deleteOriginal remove original fileName (aka mv) * @return copied fileName ID * @throws IOException when copy fails */ public String copyFile(String fileId, String destinationFolderId, String newName, boolean deleteOriginal) throws IOException { LOG.debug("[copyFile] fileId: {}; destinationFolderId: {}, newName: {}; deleteOriginal: {}.", fileId, destinationFolderId, newName, deleteOriginal); File copy = new File(); copy.setParents(Collections.singletonList(destinationFolderId)); if (!newName.isEmpty()) { copy.setName(newName); } File resultFile = drive.files().copy(fileId, copy).setFields("id, parents").execute(); String copiedResourceId = resultFile.getId(); if (deleteOriginal) { drive.files().delete(fileId).execute(); } return copiedResourceId; }
private String removeResource(String resourceId, boolean useTrash) throws IOException { if (useTrash) { drive.files().update(resourceId, new File().setTrashed(true)).execute(); } else { drive.files().delete(resourceId).execute(); } return resourceId; }
@After public void cleanupFiles() { for(String id : filesToDelete) { try { this.driveService.files().delete(id).execute(); } catch (IOException e) { System.err.println("Unable to cleanup file " + id); } } }
public void deleteGameStateSync(String fileId) throws IOException { File remoteFile = findFileByNameSync(fileId); if (remoteFile != null) { GApiGateway.drive.files().delete(remoteFile.getId()).execute(); } }
@After public void cleanupFiles() { for(String id : filesToDelete) { try { this.driveService.files().delete(id).execute(); } catch (IOException e) { System.err.println("Unable to cleanup file " + id); } } }
private String removeResource(String resourceId, boolean useTrash) throws IOException { if (useTrash) { drive.files().update(resourceId, new File().setTrashed(true)).execute(); } else { drive.files().delete(resourceId).execute(); } return resourceId; }
protected void doDelete() throws Exception { driveService.files().delete( id ).execute(); id = null; mimeType = null; }