if (fileType == SVNFileType.SYMLINK) {
dir = wcAccess.probeTry(path.getParentFile(), true, copyFromURL != null ? SVNWCAccess.INFINITE_DEPTH : 0);
} else {
dir = wcAccess.probeTry(path, true, copyFromURL != null ? SVNWCAccess.INFINITE_DEPTH : 0);
}
SVNEntry entry = null;
if (dir != null) {
entry = wcAccess.getEntry(path, true);
}
boolean replace = false;
SVNNodeKind kind = SVNFileType.getNodeKind(fileType);
if (entry != null) {
if ((copyFromURL == null && !entry.isScheduledForDeletion() && !entry.isDeleted()) || entry.getDepth() == SVNDepth.EXCLUDE) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_EXISTS, "''{0}'' is already under version control", path);
SVNErrorManager.error(err, SVNLogType.WC);
} else if (entry.getKind() != kind) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_NODE_KIND_CHANGE,
"Can''t replace ''{0}'' with a node of a different type; the deletion must be committed and the parent updated before adding ''{0}''", path);
SVNErrorManager.error(err, SVNLogType.WC);
}
replace = entry.isScheduledForDeletion();
}
SVNEntry parentEntry = wcAccess.getEntry(path.getParentFile(), false);
if (parentEntry == null) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.ENTRY_NOT_FOUND,
"Can''t find parent directory''s entry while trying to add ''{0}''", path);
SVNErrorManager.error(err, SVNLogType.WC);
}
if (parentEntry.isScheduledForDeletion()) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.WC_SCHEDULE_CONFLICT,
"Can''t add ''{0}'' to a parent directory scheduled for deletion", path);
SVNErrorManager.error(err, SVNLogType.WC);
}
Map command = new SVNHashMap();
String name = path.getName();
if (copyFromURL != null) {
if (parentEntry.getRepositoryRoot() != null && !SVNPathUtil.isAncestor(parentEntry.getRepositoryRoot(), copyFromURL.toString())) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNSUPPORTED_FEATURE,
"The URL ''{0}'' has a different repository root than its parent", copyFromURL);
SVNErrorManager.error(err, SVNLogType.WC);
}
command.put(SVNProperty.COPYFROM_URL, copyFromURL.toString());
command.put(SVNProperty.COPYFROM_REVISION, SVNProperty.toString(copyFromRev));
command.put(SVNProperty.COPIED, Boolean.TRUE.toString());
}
if (replace) {
command.put(SVNProperty.CHECKSUM, null);
command.put(SVNProperty.HAS_PROPS, Boolean.FALSE.toString());
command.put(SVNProperty.HAS_PROP_MODS, Boolean.FALSE.toString());
}
command.put(SVNProperty.SCHEDULE, SVNProperty.SCHEDULE_ADD);
command.put(SVNProperty.KIND, SVNFileType.getNodeKind(fileType).toString());
if (!(replace || copyFromURL != null)) {
command.put(SVNProperty.REVISION, "0");
}
parentDir.modifyEntry(name, command, true, false);
if (entry != null && copyFromURL == null) {
String propPath = SVNAdminUtil.getPropPath(name, entry.getKind(), false);
File propFile = dir.getFile(propPath);
SVNFileUtil.deleteFile(propFile);
}
if (replace) {
SVNProperties props = new SVNProperties();
SVNLog log = parentDir.getLog();
if (entry.getKind() == SVNNodeKind.FILE) {
props.put(SVNLog.NAME_ATTR, SVNAdminUtil.getTextBasePath(entry.getName(), false));
props.put(SVNLog.DEST_ATTR, SVNAdminUtil.getTextRevertPath(entry.getName(), false));
log.addCommand(SVNLog.MOVE, props, false);
}
createRevertProperties(parentDir, log, entry.getName(), true);
log.save();
parentDir.runLogs();
}
if (kind == SVNNodeKind.DIR) {
if (copyFromURL == null) {
SVNEntry pEntry = wcAccess.getEntry(path.getParentFile(), false);
SVNURL newURL = pEntry.getSVNURL().appendPath(name, false);
SVNURL rootURL = pEntry.getRepositoryRootURL();
String uuid = pEntry.getUUID();
ensureAdminAreaExists(path, newURL.toString(), rootURL != null ? rootURL.toString() : null, uuid, 0, depth == null ? SVNDepth.INFINITY : depth);
} else {
SVNURL rootURL = parentEntry.getRepositoryRootURL();
ensureAdminAreaExists(path, copyFromURL.toString(), rootURL != null ? rootURL.toString() : null, parentEntry.getUUID(),
copyFromRev, depth == null ? SVNDepth.INFINITY : depth);