use of org.eclipse.jgit.dircache.InvalidPathException in project winery by eclipse.
the class FilebasedRepository method rename.
@Override
public void rename(DefinitionsChildId oldId, DefinitionsChildId newId) throws IOException {
Objects.requireNonNull(oldId);
Objects.requireNonNull(newId);
if (oldId.equals(newId)) {
// we do not do anything - even not throwing an error
return;
}
Definitions definitions = this.getDefinitions(oldId);
RepositoryFileReference oldRef = BackendUtils.getRefOfDefinitions(oldId);
RepositoryFileReference newRef = BackendUtils.getRefOfDefinitions(newId);
// oldRef points to the definitions file,
// getParent() returns the directory
// we need toFile(), because we rely on FileUtils.moveDirectoryToDirectory
File oldDir = this.id2AbsolutePath(oldRef.getParent()).toFile();
File newDir = this.id2AbsolutePath(newRef.getParent()).toFile();
org.apache.commons.io.FileUtils.moveDirectory(oldDir, newDir);
// Update definitions and store it
// This also updates the definitions of componentInstanceResource
BackendUtils.updateWrapperDefinitions(newId, definitions);
// This works, because the definitions object here is the same as the definitions object treated at copyIdToFields
// newId has to be passed, because the id is final at AbstractComponentInstanceResource
BackendUtils.copyIdToFields((HasIdInIdOrNameField) definitions.getElement(), newId);
try {
BackendUtils.persist(definitions, newRef, MediaTypes.MEDIATYPE_TOSCA_DEFINITIONS);
} catch (InvalidPathException e) {
LOGGER.debug("Invalid path during write", e);
// QUICK FIX
// Somewhere, the first letter is deleted --> /odetypes/http%3A%2F%2Fwww.example.org%2F05/
// We just ignore it for now
}
}
use of org.eclipse.jgit.dircache.InvalidPathException in project winery by eclipse.
the class AbstractFileBasedRepository method duplicate.
protected void duplicate(DefinitionsChildId oldId, DefinitionsChildId newId, boolean moveOnly) throws IOException {
Objects.requireNonNull(oldId);
Objects.requireNonNull(newId);
if (oldId.equals(newId)) {
// we do not do anything - even not throwing an error
return;
}
TDefinitions definitions = this.getDefinitions(oldId);
RepositoryFileReference oldRef = BackendUtils.getRefOfDefinitions(oldId);
RepositoryFileReference newRef = BackendUtils.getRefOfDefinitions(newId);
// oldRef points to the definitions file,
// getParent() returns the directory
// we need toFile(), because we rely on FileUtils.moveDirectoryToDirectory
File oldDir = this.id2AbsolutePath(oldRef.getParent()).toFile();
File newDir = this.id2AbsolutePath(newRef.getParent()).toFile();
if (moveOnly) {
org.apache.commons.io.FileUtils.moveDirectory(oldDir, newDir);
} else {
org.apache.commons.io.FileUtils.copyDirectory(oldDir, newDir);
}
// Update definitions and store it
// This also updates the definitions of componentInstanceResource
BackendUtils.updateWrapperDefinitions(newId, definitions, this);
// This works, because the definitions object here is the same as the definitions object treated at copyIdToFields
// newId has to be passed, because the id is final at AbstractComponentInstanceResource
BackendUtils.copyIdToFields((HasIdInIdOrNameField) definitions.getElement(), newId);
try {
BackendUtils.persist(this, newId, definitions);
} catch (InvalidPathException e) {
LOGGER.debug("Invalid path during write", e);
// QUICK FIX
// Somewhere, the first letter is deleted --> /odetypes/http%3A%2F%2Fwww.example.org%2F05/
// We just ignore it for now
}
}
use of org.eclipse.jgit.dircache.InvalidPathException in project gerrit by GerritCodeReview.
the class ChangeEditModifier method createNewTree.
private static ObjectId createNewTree(Repository repository, RevCommit baseCommit, List<TreeModification> treeModifications) throws BadRequestException, IOException, InvalidChangeOperationException {
if (treeModifications.isEmpty()) {
return baseCommit.getTree();
}
ObjectId newTreeId;
try {
TreeCreator treeCreator = TreeCreator.basedOn(baseCommit);
treeCreator.addTreeModifications(treeModifications);
newTreeId = treeCreator.createNewTreeAndGetId(repository);
} catch (InvalidPathException e) {
throw new BadRequestException(e.getMessage());
}
if (ObjectId.isEqual(newTreeId, baseCommit.getTree())) {
throw new InvalidChangeOperationException("no changes were made");
}
return newTreeId;
}
Aggregations