From: Howard Chu Date: Sat, 25 Jun 2005 14:15:11 +0000 (+0000) Subject: Fix entry writing, truncate file if rewriting. X-Git-Tag: OPENLDAP_AC_BP~502 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7b245a0a55e8645d428a6ab82b192daf0aec9e67;p=openldap Fix entry writing, truncate file if rewriting. --- diff --git a/servers/slapd/back-ldif/ldif.c b/servers/slapd/back-ldif/ldif.c index a59fe576eb..a9550a5415 100644 --- a/servers/slapd/back-ldif/ldif.c +++ b/servers/slapd/back-ldif/ldif.c @@ -144,21 +144,18 @@ static char * slurp_file(int fd) { return entry; } -static int spew_file(int fd, char * spew) { - int written = 0; +static int spew_file(int fd, char * spew, int len) { int writeres = 0; - int len = strlen(spew); - char * spewptr = spew; - while(written < len) { - writeres = write(fd, spewptr, len - written); + while(len > 0) { + writeres = write(fd, spew, len); if(writeres == -1) { perror("could not spew write"); return -1; } else { - spewptr += writeres; - written += writeres; + spew += writeres; + len -= writeres; } } return writeres; @@ -171,7 +168,7 @@ static int spew_entry(Entry * e, struct berval * path) { int entry_length; char * entry_as_string; - openres = open(path->bv_val, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + openres = open(path->bv_val, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR | S_IWUSR); if(openres == -1) { if(errno == ENOENT) rs = LDAP_NO_SUCH_OBJECT; @@ -204,7 +201,7 @@ static int spew_entry(Entry * e, struct berval * path) { close(openres); } else { - spew_res = spew_file(openres, entry_as_string); + spew_res = spew_file(openres, entry_as_string, entry_length); close(openres); if(spew_res == -1) rs = LDAP_UNWILLING_TO_PERFORM;