Browse Source

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
svn/tags/lighttpd-1.4.6
Jan Kneschke 16 years ago
parent
commit
d958d547c8
  1. 24
      src/chunk.c
  2. 3
      src/chunk.h

24
src/chunk.c

@ -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;

3
src/chunk.h

@ -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);

Loading…
Cancel
Save