@Override public boolean deleteVersions(List<Versions> versions) { for (Versions versionToDelete : versions) { if (versionToDelete instanceof VersionsFileImpl) { VersionsFileImpl versionsImpl = (VersionsFileImpl) versionToDelete; VFSLeaf versionFile = versionsImpl.getVersionFile(); if (versionFile != null) { // robust against manual file system manipulation versionFile.deleteSilently(); } for (VFSRevision revisionToDelete : versionsImpl.getRevisions()) { RevisionFileImpl versionImpl = (RevisionFileImpl) revisionToDelete; VFSLeaf fileToDelete = versionImpl.getFile(); if (fileToDelete != null) { fileToDelete.deleteSilently(); } } } } return true; }
@Override public boolean deleteRevisions(Versionable currentVersion, List<VFSRevision> versionsToDelete) { VFSLeaf currentFile = (VFSLeaf) currentVersion; Versions versions = readVersions(currentFile, true); List<VFSRevision> allVersions = versions.getRevisions(); Map<String, VFSLeaf> filenamesToDelete = new HashMap<String, VFSLeaf>(allVersions.size()); for (VFSRevision versionToDelete : versionsToDelete) { RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete; for (Iterator<VFSRevision> allVersionIt = allVersions.iterator(); allVersionIt.hasNext(); ) { RevisionFileImpl allVersionImpl = (RevisionFileImpl) allVersionIt.next(); if (allVersionImpl.getFilename() != null && allVersionImpl.getFilename().equals(versionImpl.getFilename())) { allVersionIt.remove(); break; } } VFSLeaf fileToDelete = versionImpl.getFile(); if (fileToDelete != null) { filenamesToDelete.put(fileToDelete.getName(), fileToDelete); } } List<RevisionFileImpl> missingFiles = new ArrayList<>(); for (VFSRevision survivingVersion : allVersions) { RevisionFileImpl survivingVersionImpl = (RevisionFileImpl) survivingVersion; VFSLeaf revFile = survivingVersionImpl.getFile(); if (revFile == null) { missingFiles.add(survivingVersionImpl); // file is missing } else if (filenamesToDelete.containsKey(revFile.getName())) { filenamesToDelete.remove(revFile.getName()); } } if (missingFiles.size() > 0) { allVersions.removeAll(missingFiles); } for (VFSLeaf fileToDelete : filenamesToDelete.values()) { fileToDelete.deleteSilently(); } VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true); XStreamHelper.writeObject(mystream, versionFile, versions); if (currentVersion.getVersions() instanceof VersionsFileImpl) { ((VersionsFileImpl) currentVersion.getVersions()).update(versions); } return true; }