pjfanning commented on code in PR #1524:
URL: https://github.com/apache/poi/pull/1524#discussion_r4466611062


##########
poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java:
##########
@@ -989,6 +991,38 @@ public int appendRootLevelRecord(Record newRecord) {
         return addedAt;
     }
 
+    /**
+     * Removes persist objects, e.g. the slide and notes of a removed slide: 
their entries in
+     * the persist directories and the root level records these point to, 
including older
+     * versions of the records kept by incremental saves.
+     *
+     * @param persistIds the persist ids of the objects to remove
+     */
+    void removePersistObjects(Collection<Integer> persistIds) {
+        Set<Integer> removedOffsets = new HashSet<>();
+        Set<Integer> keptOffsets = new HashSet<>();
+        for (Record record : _records) {
+            if (!(record instanceof PersistPtrHolder pph)) {
+                continue;
+            }
+            Map<Integer, Integer> locations = new 
HashMap<>(pph.getSlideLocationsLookup());
+            for (Integer persistId : persistIds) {
+                Integer offset = locations.remove(persistId);
+                if (offset != null) {
+                    removedOffsets.add(offset);
+                }
+            }
+            keptOffsets.addAll(locations.values());
+            pph.clear();
+            locations.forEach(pph::addSlideLookup);
+        }
+        removedOffsets.removeAll(keptOffsets);
+
+        _records = Arrays.stream(_records)
+            .filter(r -> !(r instanceof PositionDependentRecord pdr && 
removedOffsets.contains(pdr.getLastOnDiskOffset())))

Review Comment:
   The record filter fixed the `write()` failure, but the persist directory 
entry was still removed for whatever id the notes entry held, so a malformed 
entry pointing at the `Document` failed the next load. Pushed 3c20edfc8f: 
`removeSlide` now only removes a notes entry's persist id if its core record is 
a `Notes` record. `removedSlideKeepsRecordOfBadNotesEntry` covers this and 
fails on the previous code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to