added tempfile chunks which remove the file automaticly of they are closed

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@738 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
Jan Kneschke 2005-09-26 08:53:58 +00:00
parent bd893badb9
commit d958d547c8
2 changed files with 27 additions and 0 deletions

View File

@ -58,6 +58,11 @@ static void chunk_reset(chunk *c) {
if (!c) return;
buffer_reset(c->mem);
if (c->file.is_temp && !buffer_is_empty(c->file.name)) {
unlink(c->file.name->ptr);
}
buffer_reset(c->file.name);
if (c->file.fd != -1) {
@ -247,6 +252,25 @@ buffer *chunkqueue_get_append_buffer(chunkqueue *cq) {
return c->mem;
}
chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
chunk *c;
char template[] = "/var/tmp/lighttpd-upload-XXXXXX";
c = chunkqueue_get_unused_chunk(cq);
c->type = FILE_CHUNK;
c->file.is_temp = 1;
c->offset = 0;
c->file.fd = mkstemp(template);
c->file.length = 0;
buffer_copy_string(c->file.name, template);
chunkqueue_append_chunk(cq, c);
return c;
}
off_t chunkqueue_length(chunkqueue *cq) {
off_t len = 0;
chunk *c;

View File

@ -27,6 +27,8 @@ typedef struct chunk {
char *start;
size_t length;
} mmap;
int is_temp;
} file;
/* how many bytes are already handled */
@ -54,6 +56,7 @@ int chunkqueue_prepend_buffer(chunkqueue *c, buffer *mem);
buffer * chunkqueue_get_append_buffer(chunkqueue *c);
buffer * chunkqueue_get_prepend_buffer(chunkqueue *c);
chunk * chunkqueue_get_append_tempfile(chunkqueue *cq);
int chunkqueue_remove_finished_chunks(chunkqueue *cq);