diff --git a/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java b/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java index f58cb80d..4eb97d64 100644 --- a/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java +++ b/src/main/java/org/dataone/hashstore/filehashstore/FileHashStore.java @@ -1753,20 +1753,7 @@ protected void unTagObject(String pid, String cid) // Begin deletion process addAndRenamePidRefsFileToDeleteList(pid, deleteList, absPidRefsPath); - try { - updateRefsFile(pid, absCidRefsPath, HashStoreRefUpdateTypes.remove); - if (Files.size(absCidRefsPath) == 0) { - deleteList.add(FileHashStoreUtility.renamePathForDeletion(absCidRefsPath)); - } else { - String warnMsg = "Cid referenced by pid: " + pid - + " is not empty (refs exist for cid). Skipping object " + "deletion."; - logFileHashStore.warn(warnMsg); - } - } catch (Exception e) { - logFileHashStore.warn( - "Unable to remove pid: " + pid + " from cid refs file: " + absCidRefsPath + - ". " + e.getMessage()); - } + removePidFromCidRefsAndDetermineDeletion(pid, deleteList, absCidRefsPath); deleteListOfFilesRenamedForDeletion(pid, cid, deleteList); logFileHashStore.info("Untagged pid: " + pid + " with cid: " + cid); @@ -1816,23 +1803,8 @@ protected void unTagObject(String pid, String cid) addAndRenamePidRefsFileToDeleteList(pid, deleteList, absPidRefsPath); - try { - Path absCidRefsPath = getHashStoreRefsPath(cidRead, HashStoreIdTypes.cid); - try { - updateRefsFile(pid, absCidRefsPath, HashStoreRefUpdateTypes.remove); - if (Files.size(absCidRefsPath) == 0) { - deleteList.add(FileHashStoreUtility.renamePathForDeletion(absCidRefsPath)); - } - } catch (Exception e) { - logFileHashStore.warn( - "Unable to remove pid: " + pid + " from cid refs file: " + absCidRefsPath - + ". " + e.getMessage()); - } - } catch (Exception e ) { - logFileHashStore.warn( - "Unexpected exception when attempting to remove pid: " + pid + " from cid " - + "refs file for cid: " + cidRead + ". " + e.getMessage()); - } + Path absCidRefsPath = getHashStoreRefsPath(cidRead, HashStoreIdTypes.cid); + removePidFromCidRefsAndDetermineDeletion(pid, deleteList, absCidRefsPath); deleteListOfFilesRenamedForDeletion(pid, cid, deleteList); String warnMsg = "Object with cid: " + cidRead @@ -1885,6 +1857,32 @@ protected void unTagObject(String pid, String cid) } } + /** + * Removes a pid from a given cid refs file (if it's found) and checks to see if the cid refs is + * empty before renaming this file for deletion. + * + * @param pid Persistent identifier + * @param deleteList If cid refs file needs to be deleted, list to add to + * @param absCidRefsPath Path of the cid refs file + */ + private void removePidFromCidRefsAndDetermineDeletion( + String pid, Collection deleteList, Path absCidRefsPath) { + try { + updateRefsFile(pid, absCidRefsPath, HashStoreRefUpdateTypes.remove); + if (Files.size(absCidRefsPath) == 0) { + deleteList.add(FileHashStoreUtility.renamePathForDeletion(absCidRefsPath)); + } else { + String warnMsg = "Cid referenced by pid: " + pid + + " is not empty (refs exist for cid). Skipping object " + "deletion."; + logFileHashStore.warn(warnMsg); + } + } catch (Exception e) { + logFileHashStore.warn( + "Unable to remove pid: " + pid + " from cid refs file: " + absCidRefsPath + ". " + + e.getMessage()); + } + } + /** * Deletes all the file paths contained in a given 'deleteList' *