Browse Source

Git clone (v2) fails because of stale file handle

Bug: 573770
Change-Id: I78e1c7d3e042eaef64e85bc546af207478f2e334
changes/06/182906/3
Fabio Ponciroli 2 years ago
parent
commit
67e1e9532b

+ 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);

+ 14
- 8
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,27 @@ 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);
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;
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) {
throw new StoredPackRepresentationNotAvailableException(pack,
e);
}
}
}


+ 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 Reload packfiles and try again...
} finally {
stats.timeWriting = System.currentTimeMillis() - writeStart;
stats.depth = depth;

Loading…
Cancel
Save