Пример #1
0
  @Override
  public boolean move(Versionable currentVersion, VFSContainer container) {
    VFSLeaf currentFile = (VFSLeaf) currentVersion;
    VFSLeaf fVersions = getCanonicalVersionXmlFile(currentFile, true);
    Versions versions = readVersions(currentFile, fVersions);

    VFSContainer versionContainer = getCanonicalVersionFolder(container, true);

    boolean allOk = VFSConstants.YES.equals(versionContainer.copyFrom(fVersions));
    for (VFSRevision revision : versions.getRevisions()) {
      RevisionFileImpl revisionImpl = (RevisionFileImpl) revision;
      VFSLeaf revisionFile = revisionImpl.getFile();
      if (revisionFile != null) {
        allOk &= VFSConstants.YES.equals(versionContainer.copyFrom(revisionFile));
      }
    }

    allOk &= VFSConstants.YES.equals(fVersions.delete());
    for (VFSRevision revision : versions.getRevisions()) {
      VFSLeaf revisionFile = ((RevisionFileImpl) revision).getFile();
      if (revisionFile != null) {
        allOk &= VFSConstants.YES.equals(revisionFile.delete());
      }
    }
    return allOk;
  }
Пример #2
0
  /**
   * Clean up all revisions files, xml file
   *
   * @param leaf
   */
  private void cleanUp(VFSLeaf leaf) {
    String relPath = getRelPath(leaf);
    if (relPath == null) return; // cannot handle

    File fVersion = new File(getRootVersionsFile(), relPath + ".xml");
    File fParentVersion = fVersion.getParentFile();
    if (!fParentVersion.exists()) return; // already deleted

    VFSLeaf versionLeaf = null;
    if (fVersion.exists()) {
      LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
      versionLeaf = (VFSLeaf) localVersionContainer.resolve(fVersion.getName());
    }

    if (versionLeaf == null) return; // already deleted
    Versions versions = readVersions(leaf, versionLeaf);
    for (VFSRevision versionToDelete : versions.getRevisions()) {
      RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
      VFSLeaf fileToDelete = versionImpl.getFile();
      if (fileToDelete != null) {
        fileToDelete.delete();
      }
    }
    versionLeaf.delete();
  }
Пример #3
0
  private Versions readVersions(VFSLeaf leaf, VFSLeaf fVersions) {
    if (fVersions == null) {
      return new NotVersioned();
    }

    try {
      VFSContainer fVersionContainer = fVersions.getParentContainer();
      VersionsFileImpl versions = (VersionsFileImpl) XStreamHelper.readObject(mystream, fVersions);
      versions.setVersionFile(fVersions);
      versions.setCurrentVersion((Versionable) leaf);
      if (versions.getRevisionNr() == null || versions.getRevisionNr().length() == 0) {
        versions.setRevisionNr(getNextRevisionNr(versions));
      }

      for (VFSRevision revision : versions.getRevisions()) {
        RevisionFileImpl revisionImpl = (RevisionFileImpl) revision;
        revisionImpl.setContainer(fVersionContainer);
      }
      return versions;
    } catch (Exception e) {
      log.warn("This file is not a versions XML file: " + fVersions, e);
      fVersions.delete();
      VersionsFileImpl versions = new VersionsFileImpl();
      versions.setCurrentVersion((Versionable) leaf);
      versions.setVersioned(isVersioned(leaf));
      versions.setRevisionNr(getNextRevisionNr(versions));
      log.warn("Deleted corrupt version XML file and created new version XML file: " + versions);
      // the old revisions can not be restored automatically. They are still on disk, you could
      // recover them
      // manually. This is not a perfect solution, but at least the user does not get an RS
      return versions;
    }
  }
Пример #4
0
  @Override
  public boolean delete(OrphanVersion orphan) {
    VFSLeaf versionLeaf = orphan.getVersionsLeaf();

    if (versionLeaf == null) return true; // already deleted
    Versions versions = orphan.getVersions();
    for (VFSRevision versionToDelete : versions.getRevisions()) {
      RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
      versionImpl.setContainer(orphan.getVersionsLeaf().getParentContainer());
      VFSLeaf fileToDelete = versionImpl.getFile();
      if (fileToDelete != null) {
        fileToDelete.delete();
      }
    }
    versionLeaf.delete();
    return true;
  }