Permalink
Browse files

loose: create non-existent loose file

phoenixfs used to crash on umount when the loose object being read
from didn't exist.  Fix this problem by creating the non-existent
loose object.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
  • Loading branch information...
artagnon committed Apr 1, 2012
1 parent f987936 commit 8a5cb1db3d4f4e7de85a742eb523f4a4f2aaaeba
Showing with 5 additions and 3 deletions.
  1. +5 −3 loose.c
View
@@ -65,9 +65,11 @@ void packup_loose_objects(FILE *packfh, const void *idx_data,
/* Write the zlib stream or delta */
print_sha1(sha1_digest, this_entry->sha1);
sprintf(xpath, "%s/%s", loosedir, sha1_digest);
- if (!(datafh = fopen(xpath, "rb")) ||
- (lstat(xpath, &st) < 0))
- PHOENIXFS_DBG("packup_loose_objects:: Missing %s", sha1_digest);
+ if ((lstat(xpath, &st) < 0) ||
+ !(datafh = fopen(xpath, "rb"))) {
+ PHOENIXFS_DBG("packup_loose_objects:: Creating %s", sha1_digest);
+ datafh = fopen(xpath, "wb");
+ }
PHOENIXFS_DBG("packup_loose_objects:: %s [%d]", sha1_digest, i);
fwrite(&(st.st_size), sizeof(off_t), 1, packfh);
buffer_copy_bytes(datafh, packfh, st.st_size);

0 comments on commit 8a5cb1d

Please sign in to comment.