From ff09f7e201c285af38fd1293fe5ac08019ae45dc Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 8 Apr 2008 03:23:39 -0400 Subject: [PATCH] Mark received pack file and generated .idx read-only Historically git marks pack files as read-only once they have been fully written out to disk, as this can prevent accidental modifications from destroying important data. We now mark both our pack and our index file read-only if we created them and did not fail during the processing. The test case for IndexPack was not creating the output pack or index within a temporary directory, which meant the files were being left over from the prior run. This would have caused IO errors when we ran the tests a second time as the pack and index were both marked read-only, and thus were not writable. Signed-off-by: Shawn O. Pearce --- .../tst/org/spearce/jgit/fetch/IndexPackTest.java | 8 ++++---- org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/fetch/IndexPackTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/fetch/IndexPackTest.java index e49ac997..31ec5bb8 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/fetch/IndexPackTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/fetch/IndexPackTest.java @@ -44,9 +44,9 @@ public class IndexPackTest extends RepositoryTestCase { File packFile = new File("tst/pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"); final InputStream is = new FileInputStream(packFile); try { - IndexPack pack = new IndexPack(is, new File("tmp_pack1")); + IndexPack pack = new IndexPack(is, new File(trash, "tmp_pack1")); pack.index(new TextProgressMonitor()); - PackFile file = new PackFile(db, new File("tmp_pack1.idx"), new File("tmp_pack1.pack")); + PackFile file = new PackFile(db, new File(trash, "tmp_pack1.idx"), new File(trash, "tmp_pack1.pack")); assertTrue(file.hasObject(ObjectId.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))); assertTrue(file.hasObject(ObjectId.fromString("540a36d136cf413e4b064c2b0e0a4db60f77feab"))); assertTrue(file.hasObject(ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"))); @@ -70,9 +70,9 @@ public class IndexPackTest extends RepositoryTestCase { File packFile = new File("tst/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack"); final InputStream is = new FileInputStream(packFile); try { - IndexPack pack = new IndexPack(is, new File("tmp_pack2")); + IndexPack pack = new IndexPack(is, new File(trash, "tmp_pack2")); pack.index(new TextProgressMonitor()); - PackFile file = new PackFile(db, new File("tmp_pack2.idx"), new File("tmp_pack2.pack")); + PackFile file = new PackFile(db, new File(trash, "tmp_pack2.idx"), new File(trash, "tmp_pack2.pack")); assertTrue(file.hasObject(ObjectId.fromString("02ba32d3649e510002c21651936b7077aa75ffa9"))); assertTrue(file.hasObject(ObjectId.fromString("0966a434eb1a025db6b71485ab63a3bfbea520b6"))); assertTrue(file.hasObject(ObjectId.fromString("09efc7e59a839528ac7bda9fa020dc9101278680"))); diff --git a/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java index d1318eaa..78e26a3a 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/fetch/IndexPack.java @@ -184,6 +184,11 @@ public class IndexPack { packOut.close(); inflater.end(); } + + if (dstPack != null) + dstPack.setReadOnly(); + if (dstIdx != null) + dstIdx.setReadOnly(); } catch (IOException err) { if (dstPack != null) dstPack.delete(); -- 2.11.4.GIT