Skip to content

Commit e65fed2

Browse files
committed
Revert Changes
1 parent 2497bc3 commit e65fed2

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

src/main/java/io/cdap/plugin/gcp/gcs/StorageClient.java

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,7 @@ public void mapMetaDataForAllBlobs(String path, Consumer<Map<String, String>> fu
119119
return;
120120
}
121121
GCSPath gcsPath = GCSPath.from(path);
122-
Page<Blob> blobPage;
123-
try {
124-
blobPage = storage.list(gcsPath.getBucket(), Storage.BlobListOption.prefix(gcsPath.getName()));
125-
} catch (Exception e) {
126-
String errorReason = String.format("Unable to list objects in bucket %s.", gcsPath.getBucket());
127-
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.UNKNOWN,
128-
true, GCPUtils.GCS_SUPPORTED_DOC_URL);
129-
}
122+
Page<Blob> blobPage = storage.list(gcsPath.getBucket(), Storage.BlobListOption.prefix(gcsPath.getName()));
130123
Iterator<Blob> blobIterator = blobPage.iterateAll().iterator();
131124
while (blobIterator.hasNext()) {
132125
Blob blob = blobIterator.next();
@@ -244,7 +237,8 @@ static List<GCSPath> getFilterMatchedPaths(GCSPath sourcePath, List<String> blob
244237
*/
245238
private void pairTraverse(GCSPath sourcePath, GCSPath destPath, boolean recursive, boolean overwrite,
246239
Consumer<BlobPair> consumer) {
247-
Bucket sourceBucket;
240+
241+
Bucket sourceBucket = null;
248242
try {
249243
sourceBucket = storage.get(sourcePath.getBucket());
250244
} catch (Exception e) {
@@ -258,7 +252,7 @@ private void pairTraverse(GCSPath sourcePath, GCSPath destPath, boolean recursiv
258252
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
259253
errorReason, errorReason, ErrorType.USER, true, null);
260254
}
261-
Bucket destBucket;
255+
Bucket destBucket = null;
262256
try {
263257
destBucket = storage.get(destPath.getBucket());
264258
} catch (Exception e) {
@@ -276,45 +270,24 @@ private void pairTraverse(GCSPath sourcePath, GCSPath destPath, boolean recursiv
276270

277271
boolean destinationBaseExists;
278272
String baseDestName = destPath.getName();
279-
Blob storageBlob;
280-
try {
281-
storageBlob = storage.get(BlobId.of(destPath.getBucket(), baseDestName));
282-
} catch (Exception e) {
283-
String errorReason = String.format("Unable to access GCS object '%s'.", baseDestName);
284-
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.UNKNOWN,
285-
true, GCPUtils.GCS_SUPPORTED_DOC_URL);
286-
}
287-
if (destPath.isBucket() || storageBlob != null) {
273+
if (destPath.isBucket() || storage.get(BlobId.of(destPath.getBucket(), baseDestName)) != null) {
288274
destinationBaseExists = true;
289275
} else {
290276
// if gs://bucket2/subdir doesn't exist, check if gs://bucket2/subdir/ exists
291277
// similarly, if gs://bucket2/subdir/ doesn't exist, check if gs://bucket2/subdir exists
292278
// this is because "cp dir0 subdir" and "cp dir0 subdir/" are equivalent if the 'subdir' directory exists
293279
String modifiedName = baseDestName.endsWith("/") ?
294280
baseDestName.substring(0, baseDestName.length() - 1) : baseDestName + "/";
295-
try {
296-
destinationBaseExists = storage.get(BlobId.of(destPath.getBucket(), modifiedName)) != null;
297-
} catch (Exception e) {
298-
String errorReason = String.format("Unable to access GCS object '%s'.", modifiedName);
299-
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.UNKNOWN,
300-
true, GCPUtils.GCS_SUPPORTED_DOC_URL);
301-
}
281+
destinationBaseExists = storage.get(BlobId.of(destPath.getBucket(), modifiedName)) != null;
302282
}
303283

304284
List<BlobPair> copyList = new ArrayList<>();
305285
traverse(BlobId.of(sourcePath.getBucket(), sourcePath.getName()), recursive, sourceBlob -> {
306286
BlobId destBlobID = resolve(sourcePath.getName(), sourceBlob.getBlobId().getName(),
307287
destPath, destinationBaseExists);
308288
if (!overwrite) {
309-
Blob destBlob;
310-
try {
311-
destBlob = storage.get(destBlobID);
312-
} catch (Exception e) {
313-
String errorReason = String.format("Unable to access GCS object '%s'.", destBlobID.getName());
314-
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.UNKNOWN,
315-
true, GCPUtils.GCS_SUPPORTED_DOC_URL);
316-
}
317-
// we can't just use Blob's isDirectory() because the cloud console will create a 'directory' by creating
289+
Blob destBlob = storage.get(destBlobID);
290+
// we can't just use Blob's isDirectory() because the cloud console will create a 'directory' by creating
318291
// a 0 size placeholder blob that ends with '/'. This placeholder blob's isDirectory() method returns false,
319292
// but we don't want the overwrite check to fail on it. So we explicitly ignore the check for these 0 size
320293
// placeholder blobs.

0 commit comments

Comments
 (0)