Unlock only if not deleted

This commit is contained in:
Fabio Sinibaldi 2022-05-31 16:24:23 +02:00
parent ab4a8ef1dc
commit 7df98cb40e
1 changed files with 4 additions and 2 deletions

View File

@ -366,6 +366,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
public void delete(String id,boolean force) throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException, UnauthorizedAccess, JsonProcessingException, InvalidLockException {
log.info("Deleting by ID {}, force {}",id,force);
Project doc =lock(id,"Deletion { force : "+force+"}");
boolean deleted = false;
try {
User u = UserUtils.getCurrent().asInfo().getUser();
final DataAccessPolicy policy = useCaseDescriptor.getMatching(u);
@ -387,14 +388,15 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
ws.deleteItem(folderId);
}
}finally {
if(force) super.deleteDoc(asId(id));
super.deleteDoc(asId(id));
deleted = true;
}
}
} catch (ConfigurationException | StorageHubException e) {
log.error("Exception while trying to delete {} [UCID {}]",id,useCaseDescriptor.getId());
throw new DeletionException("Unable to contact Storage ",e);
} finally{
if(doc!=null) unlockAndUpdate(doc);
if(doc!=null && !deleted) unlockAndUpdate(doc);
}
}