add another check for understand if the source and destination are the same during a copy operation

This commit is contained in:
Roberto Cirillo 2021-09-09 11:24:30 +02:00
parent 83bb788057
commit e7cd080da7
1 changed files with 7 additions and 1 deletions

View File

@ -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