use of org.eclipse.jgit.errors.LockFailedException in project gerrit by GerritCodeReview.
the class DeleteRef method deleteSingleRef.
private void deleteSingleRef(Repository r) throws IOException, ResourceConflictException {
String ref = refsToDelete.get(0);
if (prefix != null && !ref.startsWith(prefix)) {
ref = prefix + ref;
}
RefUpdate.Result result;
RefUpdate u = r.updateRef(ref);
u.setExpectedOldObjectId(r.exactRef(ref).getObjectId());
u.setNewObjectId(ObjectId.zeroId());
u.setForceUpdate(true);
refDeletionValidator.validateRefOperation(resource.getName(), identifiedUser.get(), u);
int remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
for (; ; ) {
try {
result = u.delete();
} catch (LockFailedException e) {
result = RefUpdate.Result.LOCK_FAILURE;
} catch (IOException e) {
log.error("Cannot delete " + ref, e);
throw e;
}
if (result == RefUpdate.Result.LOCK_FAILURE && --remainingLockFailureCalls > 0) {
try {
Thread.sleep(SLEEP_ON_LOCK_FAILURE_MS);
} catch (InterruptedException ie) {
// ignore
}
} else {
break;
}
}
switch(result) {
case NEW:
case NO_CHANGE:
case FAST_FORWARD:
case FORCED:
referenceUpdated.fire(resource.getNameKey(), u, ReceiveCommand.Type.DELETE, identifiedUser.get().getAccount());
break;
case REJECTED_CURRENT_BRANCH:
log.error("Cannot delete " + ref + ": " + result.name());
throw new ResourceConflictException("cannot delete current branch");
case IO_FAILURE:
case LOCK_FAILURE:
case NOT_ATTEMPTED:
case REJECTED:
case RENAMED:
default:
log.error("Cannot delete " + ref + ": " + result.name());
throw new ResourceConflictException("cannot delete: " + result.name());
}
}
use of org.eclipse.jgit.errors.LockFailedException in project egit by eclipse.
the class GitMoveDeleteHook method deleteFile.
@Override
public boolean deleteFile(final IResourceTree tree, final IFile file, final int updateFlags, final IProgressMonitor monitor) {
if (!org.eclipse.egit.core.Activator.autoStageDeletion()) {
return false;
}
// Linked resources are not files, hence not tracked by git
if (file.isLinked())
return false;
final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
if (!force && !tree.isSynchronized(file, IResource.DEPTH_ZERO))
return false;
final RepositoryMapping map = RepositoryMapping.getMapping(file);
if (map == null)
return false;
String repoRelativePath = map.getRepoRelativePath(file);
IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
IndexDiffCacheEntry indexDiffCacheEntry = indexDiffCache.getIndexDiffCacheEntry(map.getRepository());
if (indexDiffCacheEntry == null) {
return false;
}
IndexDiffData indexDiff = indexDiffCacheEntry.getIndexDiff();
if (indexDiff != null) {
if (indexDiff.getUntracked().contains(repoRelativePath))
return false;
if (indexDiff.getIgnoredNotInIndex().contains(repoRelativePath))
return false;
}
if (!file.exists())
return false;
if (file.isDerived())
return false;
DirCache dirc = null;
try {
dirc = map.getRepository().lockDirCache();
final int first = dirc.findEntry(repoRelativePath);
if (first < 0) {
dirc.unlock();
return false;
}
final DirCacheBuilder edit = dirc.builder();
if (first > 0)
edit.keep(0, first);
final int next = dirc.nextEntry(first);
if (next < dirc.getEntryCount())
edit.keep(next, dirc.getEntryCount() - next);
if (!edit.commit())
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
tree.standardDeleteFile(file, updateFlags, monitor);
} catch (LockFailedException e) {
// FIXME The index is currently locked. This notably happens during
// rebase operations. auto-staging deletions should be queued... and
// the queued job will have to double-check whether the file has
// truly been deleted or if it was only deleted to be replaced by
// another version.
// This hook only exists to automatically add changes to the index.
// If the index is currently locked, do not accept the
// responsibility of deleting the file, return false to tell the
// workspace it can continue with the standard deletion. The user
// will have to stage the deletion later on _if_ this was truly
// needed, which won't happen for calls triggered by merge
// operations from the merge strategies.
Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.getPluginId(), MessageFormat.format(CoreText.MoveDeleteHook_cannotAutoStageDeletion, file.getLocation())));
return FINISH_FOR_ME;
} catch (IOException e) {
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
} finally {
if (dirc != null)
dirc.unlock();
}
return true;
}
Aggregations