@Override public void renameFile(String from, String to, String pp) throws IOException { while (from.startsWith(File.separator)) from = from.substring(1); while (to.startsWith(File.separator)) to = to.substring(1); String fn = EncyptUtils.encString(from, Main.chunkStoreEncryptionEnabled); String tn = EncyptUtils.encString(to, Main.chunkStoreEncryptionEnabled); try { CloudBlockBlob sblob = container.getBlockBlobReference(pp + "/" + fn); CloudBlockBlob tblob = container.getBlockBlobReference(pp + "/" + tn); tblob.startCopy(sblob); while (tblob.getCopyState().getStatus() == CopyStatus.PENDING) { Thread.sleep(10); } if (tblob.getCopyState().getStatus() == CopyStatus.SUCCESS) { sblob.delete(); } else { throw new IOException( "unable to rename file " + fn + " because " + tblob.getCopyState().getStatus().name() + " : " + tblob.getCopyState().getStatusDescription()); } } catch (Exception e) { throw new IOException(e); } }
private void copyBlob(CloudBlob blob, CloudBlobDirectory newParent) throws IOException { checkArgument(blob instanceof CloudBlockBlob, "Only page blobs are supported for the rename"); try { String blobName = getName(blob); CloudBlockBlob newBlob = newParent.getBlockBlobReference(blobName); newBlob.startCopy(blob.getUri()); boolean isStatusPending = true; while (isStatusPending) { newBlob.downloadAttributes(); if (newBlob.getCopyState().getStatus() == CopyStatus.PENDING) { Thread.sleep(100); } else { isStatusPending = false; } } CopyStatus finalStatus = newBlob.getCopyState().getStatus(); if (newBlob.getCopyState().getStatus() != CopyStatus.SUCCESS) { throw new IOException("Invalid copy status for " + blob.getUri().getPath() + ": " + finalStatus); } } catch (StorageException | InterruptedException | URISyntaxException e) { throw new IOException(e); } }
private void copyBlob(CloudBlob blob, CloudBlobDirectory newParent) throws IOException { checkArgument(blob instanceof CloudBlockBlob, "Only page blobs are supported for the rename"); try { String blobName = getName(blob); CloudBlockBlob newBlob = newParent.getBlockBlobReference(blobName); newBlob.startCopy(blob.getUri()); boolean isStatusPending = true; while (isStatusPending) { newBlob.downloadAttributes(); if (newBlob.getCopyState().getStatus() == CopyStatus.PENDING) { Thread.sleep(100); } else { isStatusPending = false; } } CopyStatus finalStatus = newBlob.getCopyState().getStatus(); if (newBlob.getCopyState().getStatus() != CopyStatus.SUCCESS) { throw new IOException("Invalid copy status for " + blob.getUri().getPath() + ": " + finalStatus); } } catch (StorageException | InterruptedException | URISyntaxException e) { throw new IOException(e); } }
throw new DataStoreException( String.format("Cannot update lastModified for blob. identifier=%s status=%s", key, blob.getCopyState().getStatusDescription()));
BlobTestHelper.waitForCopy(copy); assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), copy.getCopyState().getSource().getPath()); assertEquals(data.length(), copy.getCopyState().getTotalBytes().intValue()); assertEquals(data.length(), copy.getCopyState().getBytesCopied().intValue()); assertEquals(copyId, copy.getCopyState().getCopyId()); assertTrue(copy.getCopyState().getCompletionTime().compareTo(new Date(calendar.get(Calendar.MINUTE) - 1)) > 0);
destination.downloadAttributes(); assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getServiceClient().getCredentials().transformUri(source.getUri()).getPath(), destination.getCopyState().getSource().getPath()); assertEquals(data.length(), destination.getCopyState().getTotalBytes().intValue()); assertEquals(data.length(), destination.getCopyState().getBytesCopied().intValue()); assertEquals(copyId, destination.getCopyState().getCopyId()); assertTrue(0 < destination.getCopyState().getCompletionTime().compareTo( new Date(calendar.get(Calendar.MINUTE) - 6)));
assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getSnapshotQualifiedUri().getPath(), destination.getCopyState().getSource().getPath()); assertEquals(data.length(), destination.getCopyState().getTotalBytes().intValue()); assertEquals(data.length(), destination.getCopyState().getBytesCopied().intValue()); assertEquals(copyId, destination.getProperties().getCopyState().getCopyId()); assertTrue(destination.getCopyState().getCompletionTime() .compareTo(new Date(calendar.get(Calendar.MINUTE) - 1)) > 0); copyDestination.abortCopy(destination.getCopyState().getCopyId());
assertEquals(CopyStatus.SUCCESS, destination.getCopyState().getStatus()); assertEquals(source.getServiceClient().getCredentials().transformUri(source.getUri()).getPath(), destination.getCopyState().getSource().getPath()); assertEquals(data.length(), destination.getCopyState().getTotalBytes().intValue()); assertEquals(data.length(), destination.getCopyState().getBytesCopied().intValue()); assertEquals(copyId, destination.getProperties().getCopyState().getCopyId()); destination.abortCopy(destination.getCopyState().getCopyId()); fail();
assertEquals(copyId, copySas.getCopyState().getCopyId());
assertEquals(CopyStatus.SUCCESS, copy.getCopyState().getStatus()); assertEquals(data, copy.downloadText(Constants.UTF8_CHARSET, null, null, null)); assertEquals(copyId, copy.getProperties().getCopyState().getCopyId());