From: Junio C Hamano <junkio@cox.net>
To: Andy Whitcroft <apw@shadowen.org>
Cc: "Michael S. Tsirkin" <mst@mellanox.co.il>,
Linus Torvalds <torvalds@osdl.org>,
git@vger.kernel.org
Subject: Re: tree corrupted on disk quota full
Date: Thu, 11 Jan 2007 13:27:44 -0800 [thread overview]
Message-ID: <7vodp52qzz.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <45A6A97F.5080008@shadowen.org> (Andy Whitcroft's message of "Thu, 11 Jan 2007 21:17:51 +0000")
Andy Whitcroft <apw@shadowen.org> writes:
> The call was intended to replace a common idiom:
>
> if (xwrite(fd, buf, size) != size)
> error
>
> write_in_full() is intended as a drop in replacement for that. On a
> short write we will return a short count and that will fail such a test.
> The call basically implements the standard write() call semantic with
> maximum attempts to complete.
You are both right ;-). I would have these fixups on top of
Linus's.
---
diff --git a/config.c b/config.c
index 2cd0263..733fb1a 100644
--- a/config.c
+++ b/config.c
@@ -694,11 +694,9 @@ int git_config_set_multivar(const char* key, const char* value,
store.key = (char*)key;
if (!store_write_section(fd, key) ||
- !store_write_pair(fd, key, value)) {
- ret = write_error();
- goto out_free;
- }
- } else{
+ !store_write_pair(fd, key, value))
+ goto write_err_out;
+ } else {
struct stat st;
char* contents;
int i, copy_begin, copy_end, new_line = 0;
@@ -777,31 +775,33 @@ int git_config_set_multivar(const char* key, const char* value,
/* write the first part of the config */
if (copy_end > copy_begin) {
- write_in_full(fd, contents + copy_begin,
- copy_end - copy_begin);
- if (new_line)
- write_in_full(fd, "\n", 1);
+ if (write_in_full(fd, contents + copy_begin,
+ copy_end - copy_begin) <
+ copy_end - copy_begin)
+ goto write_err_out;
+ if (new_line &&
+ write_in_full(fd, "\n", 1) != 1)
+ goto write_err_out;
}
copy_begin = store.offset[i];
}
/* write the pair (value == NULL means unset) */
if (value != NULL) {
- if (store.state == START)
- if (!store_write_section(fd, key)) {
- ret = write_error();
- goto out_free;
- }
- if (!store_write_pair(fd, key, value)) {
- ret = write_error();
- goto out_free;
+ if (store.state == START) {
+ if (!store_write_section(fd, key))
+ goto write_err_out;
}
+ if (!store_write_pair(fd, key, value))
+ goto write_err_out;
}
/* write the rest of the config */
if (copy_begin < st.st_size)
- write_in_full(fd, contents + copy_begin,
- st.st_size - copy_begin);
+ if (write_in_full(fd, contents + copy_begin,
+ st.st_size - copy_begin) <
+ st.st_size - copy_begin)
+ goto write_err_out;
munmap(contents, st.st_size);
unlink(config_filename);
@@ -824,6 +824,11 @@ out_free:
free(lock_file);
}
return ret;
+
+write_err_out:
+ ret = write_error();
+ goto out_free;
+
}
int git_config_rename_section(const char *old_name, const char *new_name)
diff --git a/index-pack.c b/index-pack.c
index 8d10d6b..72e0962 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -814,7 +814,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
char buf[48];
int len = snprintf(buf, sizeof(buf), "%s\t%s\n",
report, sha1_to_hex(sha1));
- write_in_full(1, buf, len);
+ write_or_die(1, buf, len);
/*
* Let's just mimic git-unpack-objects here and write
next prev parent reply other threads:[~2007-01-11 21:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-11 12:57 tree corrupted on disk quota full Michael S. Tsirkin
2007-01-11 13:40 ` Andreas Ericsson
2007-01-11 13:43 ` Andy Whitcroft
2007-01-11 13:59 ` Michael S. Tsirkin
2007-01-11 14:28 ` Andreas Ericsson
2007-01-11 18:31 ` Linus Torvalds
2007-01-11 19:19 ` Linus Torvalds
2007-01-11 20:03 ` Linus Torvalds
2007-01-11 21:02 ` Junio C Hamano
2007-01-11 21:17 ` Andy Whitcroft
2007-01-11 21:27 ` Junio C Hamano [this message]
2007-01-11 22:09 ` Better error messages for corrupt databases Linus Torvalds
2007-01-12 0:40 ` Shawn O. Pearce
2007-01-11 21:59 ` tree corrupted on disk quota full Linus Torvalds
2007-01-11 22:10 ` Andy Whitcroft
2007-01-11 22:32 ` Linus Torvalds
2007-01-11 21:11 ` Michael S. Tsirkin
2007-01-11 21:50 ` Linus Torvalds
2007-01-11 21:58 ` Michael S. Tsirkin
2007-01-11 22:24 ` Linus Torvalds
2007-01-11 22:39 ` Michael S. Tsirkin
2007-01-12 0:42 ` Linus Torvalds
2007-01-12 0:51 ` Shawn O. Pearce
2007-01-13 0:53 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vodp52qzz.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=apw@shadowen.org \
--cc=git@vger.kernel.org \
--cc=mst@mellanox.co.il \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox