git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Create $GIT_DIR/objects/pack if missing during renameAndOpenPack

From
Shawn O. Pearce <spearce@spearce.org>
Date
May 10, 2009, 21:30 UTC
Message-ID
<20090510213046.GC30527@spearce.org>
In-Reply-To
<693615.98383.qm@web27802.mail.ukl.yahoo.com>

Its OK for the objects/pack directory to be missing, an empty repository doesn't have to have it. C Git's `git repack` will automatically create the directory if it is not present, so we need to do the same behavior here.

When the directory doesn't exist, we try to create it, but we may have creation fail if another concurrent thread/process also made the directory at the same time, hence we test once more after creation failure before throwing the exception.

Found-by: Mark Struberg <struberg@yahoo.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
  Mark Struberg <struberg@yahoo.de> wrote:
  > 
  > If I use jgit to push to this repo it crashes because it cannot write to the pack folder. If I
  > mkdir the object/pack folder in my origin repo, everything runs smooth.
  
  Yea, that's legal.  This patch should fix it.
  
 .../src/org/spearce/jgit/transport/IndexPack.java  |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
index b2bcbb7..1eb40d4 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/IndexPack.java
@@ -1037,6 +1037,14 @@ public PackLock renameAndOpenPack(final String lockMessage)
 		final File finalIdx = new File(packDir, "pack-" + name + ".idx");
 		final PackLock keep = new PackLock(finalPack);
 
+		if (!packDir.exists() && !packDir.mkdir() && !packDir.exists()) {
+			// The objects/pack directory isn't present, and we are unable
+			// to create it. There is no way to move this pack in.
+			//
+			cleanupTemporaryFiles();
+			throw new IOException("Cannot create " + packDir.getAbsolutePath());
+		}
+
 		if (finalPack.exists()) {
 			// If the pack is already present we should never replace it.
 			//
-- 
1.6.3.195.gad81
Previous: Mark StrubergNext: Robin Rosenberg
Message 2 of 4 in “[JGIT] exception while pushing if no objects/pack directory exists in origin repo”
  1. Mark StrubergMay 9, 2009
  2. Create $GIT_DIR/objects/pack if missing during renameAndOpenPackShawn O. Pearce, May 10, 2009
  3. Robin RosenbergMay 10, 2009
  4. Shawn O. PearceMay 10, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.