Fix #1150: remove compress cache file if compression or write failed

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2101 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
Stefan Bühler 2008-02-27 19:36:34 +00:00
parent 4875c125eb
commit 87d3e8e41e
2 changed files with 29 additions and 10 deletions

1
NEWS
View File

@ -42,6 +42,7 @@ NEWS
* do not suppress content on "307 Temporary Redirect" (#1412)
* fixed Content-Length header if response body gets removed in connections.c (#1412, part 2)
* do not generate a "Content-Length: 0" header for HEAD requests, added test too
* remove compress cache file if compression or write failed (#1150)
- 1.4.18 - 2007-09-09

View File

@ -439,6 +439,11 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, bu
close(ofd);
/* Remove the incomplete cache file, so that later hits aren't served from it */
if (-1 == unlink(p->ofn->ptr)) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno));
}
return -1;
}
@ -448,6 +453,12 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, bu
close(ofd);
close(ifd);
/* Remove the incomplete cache file, so that later hits aren't served from it */
if (-1 == unlink(p->ofn->ptr)) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno));
}
return -1;
}
@ -470,22 +481,29 @@ static int deflate_file_to_file(server *srv, connection *con, plugin_data *p, bu
break;
}
if (-1 == (r = write(ofd, p->b->ptr, p->b->used))) {
munmap(start, sce->st.st_size);
close(ofd);
close(ifd);
return -1;
}
if ((size_t)r != p->b->used) {
if (ret == 0) {
r = write(ofd, p->b->ptr, p->b->used);
if (-1 == r) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "writing cachefile", p->ofn, "failed:", strerror(errno));
ret = -1;
} else if ((size_t)r != p->b->used) {
log_error_write(srv, __FILE__, __LINE__, "sbs", "writing cachefile", p->ofn, "failed: not enough bytes written");
ret = -1;
}
}
munmap(start, sce->st.st_size);
close(ofd);
close(ifd);
if (ret != 0) return -1;
if (ret != 0) {
/* Remove the incomplete cache file, so that later hits aren't served from it */
if (-1 == unlink(p->ofn->ptr)) {
log_error_write(srv, __FILE__, __LINE__, "sbss", "unlinking incomplete cachefile", p->ofn, "failed:", strerror(errno));
}
return -1;
}
buffer_copy_string_buffer(con->physical.path, p->ofn);