Exemplo n.º 1
0
  /**
   * Get the canonical path to the file's meta file.
   *
   * @param bcPath
   * @return String
   */
  private VFSLeaf getCanonicalVersionXmlFile(VFSItem item, boolean create) {
    File f = getOriginFile(item);
    if (!f.exists()) {
      return null;
    }

    String relPath = getRelPath(item);
    if (relPath == null) {
      // cannot handle
      return null;
    }

    File fVersion = new File(getRootVersionsFile(), relPath + ".xml");
    File fParentVersion = fVersion.getParentFile();
    if (!fParentVersion.exists() && create) {
      fParentVersion.mkdirs();
    }

    if (fVersion.exists()) {
      LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
      return (VFSLeaf) localVersionContainer.resolve(fVersion.getName());
    } else if (create) {
      LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
      VersionsFileImpl versions = new VersionsFileImpl();
      versions.setVersioned(isVersioned(item));
      versions.setRevisionNr(getNextRevisionNr(versions));
      VFSLeaf fVersions = localVersionContainer.createChildLeaf(fVersion.getName());
      XStreamHelper.writeObject(mystream, fVersions, versions);
      return fVersions;
    }
    return null;
  }
Exemplo n.º 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();
  }