From e7cd080da72232b395ee519c6a75592c5aee7560 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Thu, 9 Sep 2021 11:24:30 +0200 Subject: [PATCH] add another check for understand if the source and destination are the same during a copy operation --- .../transport/backend/operation/SoftCopyOperator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/contentmanagement/blobstorage/transport/backend/operation/SoftCopyOperator.java b/src/main/java/org/gcube/contentmanagement/blobstorage/transport/backend/operation/SoftCopyOperator.java index f94fecf..84d92eb 100644 --- a/src/main/java/org/gcube/contentmanagement/blobstorage/transport/backend/operation/SoftCopyOperator.java +++ b/src/main/java/org/gcube/contentmanagement/blobstorage/transport/backend/operation/SoftCopyOperator.java @@ -86,6 +86,7 @@ public class SoftCopyOperator extends SoftCopy { // if it contains a link field, then I'm going to retrieve the related payload sourceObject = mongoPrimaryInstance.retrieveLinkPayload(sourceObject); ObjectId sourceId=(ObjectId)sourceObject.getId(); + logger.debug("source id is "+sourceId); InputStream is= sourceObject.getInputStream(); resource.setInputStream(is); GridFSDBFile dest = null; @@ -104,11 +105,16 @@ public class SoftCopyOperator extends SoftCopy { ObjectId removedId=null; // if the destination location is not empty if (dest != null){ + String destId=dest.getId().toString(); + logger.debug("destination id is "+sourceId); + // in this case the source and dest are the same object + if(sourceId.equals(destId)) + return destId; // remove the destination file. The third parameter to true replace the file otherwise the remote id is returned if(resource.isReplace()){ removedId = mongoPrimaryInstance.removeFile(resource, null, resource.isReplace(), null, dest); }else{ - return dest.getId().toString(); + return destId; } } // get metacollection instance