001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.wc.admin;
013:
014: import java.io.BufferedReader;
015: import java.io.File;
016: import java.io.IOException;
017: import java.io.InputStreamReader;
018:
019: import org.tmatesoft.svn.core.SVNErrorCode;
020: import org.tmatesoft.svn.core.SVNErrorMessage;
021: import org.tmatesoft.svn.core.SVNException;
022: import org.tmatesoft.svn.core.internal.wc.SVNErrorManager;
023: import org.tmatesoft.svn.core.internal.wc.SVNFileType;
024: import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
025:
026: /**
027: * @version 1.1.1
028: * @author TMate Software Ltd.
029: */
030: class SVNAdminArea14Factory extends SVNAdminAreaFactory {
031:
032: public static final int WC_FORMAT = 8;
033:
034: protected void doCreateVersionedDirectory(File path, String url,
035: String rootURL, String uuid, long revNumber)
036: throws SVNException {
037: SVNAdminArea adminArea = new SVNAdminArea14(path);
038: adminArea.createVersionedDirectory(path, url, rootURL, uuid,
039: revNumber, true);
040: }
041:
042: protected SVNAdminArea doOpen(File path, int version)
043: throws SVNException {
044: if (version != WC_FORMAT) {
045: return null;
046: }
047: return new SVNAdminArea14(path);
048: }
049:
050: protected SVNAdminArea doUpgrade(SVNAdminArea adminArea)
051: throws SVNException {
052: if (adminArea == null
053: || adminArea.getClass() == SVNAdminArea14.class) {
054: return adminArea;
055: }
056: SVNAdminArea14 newestAdminArea = new SVNAdminArea14(adminArea
057: .getRoot());
058: newestAdminArea.setLocked(true);
059: return newestAdminArea.upgradeFormat(adminArea);
060: }
061:
062: public int getSupportedVersion() {
063: return WC_FORMAT;
064: }
065:
066: protected int doCheckWC(File path) throws SVNException {
067: File adminDir = new File(path, SVNFileUtil
068: .getAdminDirectoryName());
069: File entriesFile = new File(adminDir, "entries");
070: int formatVersion = -1;
071:
072: BufferedReader reader = null;
073: String line = null;
074:
075: try {
076: reader = new BufferedReader(new InputStreamReader(
077: SVNFileUtil.openFileForReading(entriesFile),
078: "UTF-8"));
079: line = reader.readLine();
080: } catch (IOException e) {
081: SVNErrorMessage err = SVNErrorMessage
082: .create(SVNErrorCode.IO_ERROR,
083: "Cannot read entries file ''{0}'': {1}",
084: new Object[] { entriesFile,
085: e.getLocalizedMessage() });
086: SVNErrorManager.error(err, e);
087: } catch (SVNException svne) {
088: SVNFileType type = SVNFileType.getType(path);
089: if (type != SVNFileType.DIRECTORY || !entriesFile.exists()) {
090: if (type == SVNFileType.NONE) {
091: SVNErrorMessage err = SVNErrorMessage.create(
092: SVNErrorCode.IO_ERROR,
093: "''{0}'' does not exist", path);
094: SVNErrorManager.error(err);
095: }
096: return 0;
097: }
098: throw svne;
099: } finally {
100: SVNFileUtil.closeFile(reader);
101: }
102:
103: if (line == null || line.length() == 0) {
104: SVNErrorMessage err = SVNErrorMessage.create(
105: SVNErrorCode.STREAM_UNEXPECTED_EOF,
106: "Reading ''{0}''", entriesFile);
107: SVNErrorManager.error(err);
108: }
109:
110: try {
111: formatVersion = Integer.parseInt(line.trim());
112: } catch (NumberFormatException e) {
113: SVNErrorMessage err = SVNErrorMessage.create(
114: SVNErrorCode.BAD_VERSION_FILE_FORMAT,
115: "First line of ''{0}'' contains non-digit",
116: entriesFile);
117: SVNErrorManager.error(err);
118: }
119: return formatVersion;
120: }
121:
122: protected int getVersion(File path) throws SVNException {
123: File adminDir = new File(path, SVNFileUtil
124: .getAdminDirectoryName());
125: File entriesFile = new File(adminDir, "entries");
126: int formatVersion = -1;
127:
128: BufferedReader reader = null;
129: String line = null;
130:
131: try {
132: reader = new BufferedReader(new InputStreamReader(
133: SVNFileUtil.openFileForReading(entriesFile),
134: "UTF-8"));
135: line = reader.readLine();
136: } catch (IOException e) {
137: SVNErrorMessage err = SVNErrorMessage
138: .create(SVNErrorCode.IO_ERROR,
139: "Cannot read entries file ''{0}'': {1}",
140: new Object[] { entriesFile,
141: e.getLocalizedMessage() });
142: SVNErrorManager.error(err, e);
143: } catch (SVNException svne) {
144: SVNErrorMessage err = SVNErrorMessage.create(
145: SVNErrorCode.WC_NOT_DIRECTORY,
146: "''{0}'' is not a working copy", path);
147: err.setChildErrorMessage(svne.getErrorMessage());
148: SVNErrorManager.error(err, svne);
149: } finally {
150: SVNFileUtil.closeFile(reader);
151: }
152:
153: if (line == null || line.length() == 0) {
154: SVNErrorMessage err = SVNErrorMessage.create(
155: SVNErrorCode.STREAM_UNEXPECTED_EOF,
156: "Reading ''{0}''", entriesFile);
157: SVNErrorMessage err1 = SVNErrorMessage.create(
158: SVNErrorCode.WC_NOT_DIRECTORY,
159: "''{0}'' is not a working copy", path);
160: err1.setChildErrorMessage(err);
161: SVNErrorManager.error(err1);
162: }
163:
164: try {
165: formatVersion = Integer.parseInt(line.trim());
166: } catch (NumberFormatException e) {
167: SVNErrorMessage err = SVNErrorMessage.create(
168: SVNErrorCode.BAD_VERSION_FILE_FORMAT,
169: "First line of ''{0}'' contains non-digit",
170: entriesFile);
171: SVNErrorMessage err1 = SVNErrorMessage.create(
172: SVNErrorCode.WC_NOT_DIRECTORY,
173: "''{0}'' is not a working copy", path);
174: err1.setChildErrorMessage(err);
175: SVNErrorManager.error(err1);
176: }
177: return formatVersion;
178: }
179: }
|