Esempio n. 1
0
  public static SVNAdminArea open(File path, Level logLevel) throws SVNException {
    SVNErrorMessage error = null;
    int wcFormatVersion = -1;
    Collection enabledFactories = getSelector().getEnabledFactories(path, ourFactories, false);
    File adminDir = new Resource(path, SVNFileUtil.getAdminDirectoryName());
    File entriesFile = new Resource(adminDir, "entries");
    if (adminDir.isDirectory() && entriesFile.isFile()) {
      for (Iterator factories = enabledFactories.iterator(); factories.hasNext(); ) {
        SVNAdminAreaFactory factory = (SVNAdminAreaFactory) factories.next();
        try {
          wcFormatVersion = factory.getVersion(path);
          if (wcFormatVersion > factory.getSupportedVersion()) {
            SVNErrorMessage err =
                SVNErrorMessage.create(
                    SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                    "The path ''{0}'' appears to be part of a Subversion 1.7 or greater\n"
                        + "working copy.  Please upgrade your Subversion client to use this\n"
                        + "working copy.",
                    path);
            SVNErrorManager.error(err, SVNLogType.WC);
          } else if (wcFormatVersion < factory.getSupportedVersion()) {
            SVNErrorMessage err =
                SVNErrorMessage.create(
                    SVNErrorCode.WC_UNSUPPORTED_FORMAT,
                    "Working copy format of {0} is too old ({1}); please check out your working copy again",
                    new Object[] {path, new Integer(wcFormatVersion)});
            SVNErrorManager.error(err, SVNLogType.WC);
          }
        } catch (SVNException e) {
          if (error != null) {
            error.setChildErrorMessage(e.getErrorMessage());
          } else {
            error = e.getErrorMessage();
          }
          continue;
        }

        SVNAdminArea adminArea = factory.doOpen(path, wcFormatVersion);
        if (adminArea != null) {
          adminArea.setWorkingCopyFormatVersion(wcFormatVersion);
          return adminArea;
        }
      }
    }
    if (error == null) {
      if (path != null) {
        checkWCNG(path.getAbsoluteFile(), path);
      }
      error =
          SVNErrorMessage.create(
              SVNErrorCode.WC_NOT_DIRECTORY, "''{0}'' is not a working copy", path);
    }
    if (error.getErrorCode() == SVNErrorCode.WC_UNSUPPORTED_FORMAT) {
      error.setChildErrorMessage(null);
    }
    SVNErrorManager.error(error, logLevel, SVNLogType.WC);
    return null;
  }
Esempio n. 2
0
  private static boolean checkAdminAreaExists(File dir, String url, long revision)
      throws SVNException {
    File adminDir = new Resource(dir, SVNFileUtil.getAdminDirectoryName());
    if (adminDir.exists() && !adminDir.isDirectory()) {
      SVNErrorMessage err =
          SVNErrorMessage.create(
              SVNErrorCode.WC_OBSTRUCTED_UPDATE, "''{0}'' is not a directory", dir);
      SVNErrorManager.error(err, SVNLogType.WC);
    } else if (!adminDir.exists()) {
      return false;
    }

    boolean wcExists = false;
    try {
      readFormatVersion(adminDir);
      wcExists = true;
    } catch (SVNException svne) {
      return false;
    }

    if (wcExists) {
      SVNWCAccess wcAccess = SVNWCAccess.newInstance(null);
      SVNAdminArea adminArea = null;
      SVNEntry entry = null;
      try {
        adminArea = wcAccess.open(dir, false, 0);
        entry = adminArea.getVersionedEntry(adminArea.getThisDirName(), false);
      } finally {
        wcAccess.closeAdminArea(dir);
      }
      if (!entry.isScheduledForDeletion()) {
        if (entry.getRevision() != revision) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_OBSTRUCTED_UPDATE,
                  "Revision {0} doesn''t match existing revision {1} in ''{2}''",
                  new Object[] {new Long(revision), new Long(entry.getRevision()), dir});
          SVNErrorManager.error(err, SVNLogType.WC);
        }
        if (!url.equals(entry.getURL())) {
          SVNErrorMessage err =
              SVNErrorMessage.create(
                  SVNErrorCode.WC_OBSTRUCTED_UPDATE,
                  "URL ''{0}'' doesn''t match existing URL ''{1}'' in ''{2}''",
                  new Object[] {url, entry.getURL(), dir});
          SVNErrorManager.error(err, SVNLogType.WC);
        }
      }
    }
    return wcExists;
  }