Browse Source

Git clone (v2) fails because of stale file handle

Bug: 573770
Change-Id: I78e1c7d3e042eaef64e85bc546af207478f2e334
changes/06/182906/4
Fabio Ponciroli 2 years ago
parent
commit
90057f608f

+ 36
- 0
org.eclipse.jgit/src/org/eclipse/jgit/errors/StoredPackRepresentationNotAvailableException.java View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2010, Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package org.eclipse.jgit.errors;

import org.eclipse.jgit.internal.storage.file.Pack;

/**
* A previously selected representation is no longer available.
*/
public class StoredPackRepresentationNotAvailableException extends Exception {
//TODO remove unused ObjectToPack in 5.0
private static final long serialVersionUID = 1L;

/**
* Construct an error for an object.
*
* @param pack
* the object whose current representation is no longer present.
* @param cause
* cause
* @since 5.13
*/
public StoredPackRepresentationNotAvailableException(Pack pack,
Throwable cause) {
super(cause);
// Do nothing.
}
}

+ 3
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalCachedPack.java View File

@@ -15,6 +15,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.errors.StoredPackRepresentationNotAvailableException;
import org.eclipse.jgit.internal.storage.pack.CachedPack;
import org.eclipse.jgit.internal.storage.pack.ObjectToPack;
import org.eclipse.jgit.internal.storage.pack.PackExt;
@@ -49,7 +51,7 @@ class LocalCachedPack extends CachedPack {
}

void copyAsIs(PackOutputStream out, WindowCursor wc)
throws IOException {
throws IOException, StoredPackRepresentationNotAvailableException {
for (Pack pack : getPacks())
pack.copyPackAsIs(out, wc);
}

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java View File

@@ -45,6 +45,7 @@ import org.eclipse.jgit.errors.NoPackSignatureException;
import org.eclipse.jgit.errors.PackInvalidException;
import org.eclipse.jgit.errors.PackMismatchException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.errors.StoredPackRepresentationNotAvailableException;
import org.eclipse.jgit.errors.UnpackException;
import org.eclipse.jgit.errors.UnsupportedPackIndexVersionException;
import org.eclipse.jgit.errors.UnsupportedPackVersionException;
@@ -375,7 +376,7 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
}

void copyPackAsIs(PackOutputStream out, WindowCursor curs)
throws IOException {
throws IOException, StoredPackRepresentationNotAvailableException {
// Pin the first window, this ensures the length is accurate.
curs.pin(this, 0);
curs.copyPackAsIs(this, length, out);

+ 24
- 9
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java View File

@@ -24,6 +24,7 @@ import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.errors.StoredPackRepresentationNotAvailableException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.pack.CachedPack;
import org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs;
@@ -235,22 +236,36 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
/** {@inheritDoc} */
@Override
public void copyPackAsIs(PackOutputStream out, CachedPack pack)
throws IOException {
throws IOException, StoredPackRepresentationNotAvailableException {
((LocalCachedPack) pack).copyAsIs(out, this);
}

void copyPackAsIs(final Pack pack, final long length,
final PackOutputStream out) throws IOException {
final PackOutputStream out) throws IOException, StoredPackRepresentationNotAvailableException {
long position = 12;
long remaining = length - (12 + 20);
while (0 < remaining) {
pin(pack, position);

int ptr = (int) (position - window.start);
int n = (int) Math.min(window.size() - ptr, remaining);
window.write(out, position, n);
position += n;
remaining -= n;
boolean reloadedPacks = false;
COPYPACK: for (; ; ) {
try {
pin(pack, position);

int ptr = (int) (position - window.start);
int n = (int) Math.min(window.size() - ptr, remaining);
window.write(out, position, n);
position += n;
remaining -= n;
} catch(Exception e){
if (reloadedPacks) {
throw new StoredPackRepresentationNotAvailableException(pack, e);
} else {
reloadedPacks = true;
WindowCache.purge(pack);
continue COPYPACK;
}
}
break COPYPACK;
}
}
}


+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectReuseAsIs.java View File

@@ -16,6 +16,7 @@ import java.util.List;

import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.errors.StoredPackRepresentationNotAvailableException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
import org.eclipse.jgit.lib.ProgressMonitor;
@@ -184,7 +185,7 @@ public interface ObjectReuseAsIs {
* the pack cannot be read, or stream did not accept a write.
*/
void copyPackAsIs(PackOutputStream out, CachedPack pack)
throws IOException;
throws IOException, StoredPackRepresentationNotAvailableException;

/**
* Obtain the available cached packs that match the bitmap and update

+ 3
- 0
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java View File

@@ -57,6 +57,7 @@ import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.SearchForReuseTimeout;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.errors.StoredPackRepresentationNotAvailableException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndexWriterV1;
@@ -1286,6 +1287,8 @@ public class PackWriter implements AutoCloseable {
}
writeChecksum(out);
out.flush();
} catch (StoredPackRepresentationNotAvailableException s) {
//XXX Log cannot load packfile...
} finally {
stats.timeWriting = System.currentTimeMillis() - writeStart;
stats.depth = depth;

Loading…
Cancel
Save