Ticket #1027: lighttpd-1.4.18-compress-mkdir.patch
| File lighttpd-1.4.18-compress-mkdir.patch, 2.8 kB (added by spillgroup, 4 months ago) |
|---|
-
b/src/mod_compress.c
old new 102 102 return HANDLER_GO_ON; 103 103 } 104 104 105 // 0 on success, -1 for error 106 int mkdir_recursive(char *dir) { 107 char *p = dir; 108 109 if (!dir || !dir[0]) 110 return 0; 111 112 while ((p = strchr(p + 1, '/')) != NULL) { 113 114 *p = '\0'; 115 if ((mkdir(dir, 0700) != 0) && (errno != EEXIST)) { 116 *p = '/'; 117 return -1; 118 } 119 120 *p++ = '/'; 121 if (!*p) return 0; // Ignore trailing slash 122 } 123 124 return (mkdir(dir, 0700) != 0) && (errno != EEXIST) ? -1 : 0; 125 } 126 127 // 0 on success, -1 for error 128 int mkdir_for_file(char *filename) { 129 char *p = filename; 130 131 if (!filename || !filename[0]) 132 return -1; 133 134 while ((p = strchr(p + 1, '/')) != NULL) { 135 136 *p = '\0'; 137 if ((mkdir(filename, 0700) != 0) && (errno != EEXIST)) { 138 *p = '/'; 139 return -1; 140 } 141 142 *p++ = '/'; 143 if (!*p) return -1; // Unexpected trailing slash in filename 144 } 145 146 return 0; 147 } 148 105 149 SETDEFAULTS_FUNC(mod_compress_setdefaults) { 106 150 plugin_data *p = p_d; 107 151 size_t i = 0; … … 134 178 } 135 179 136 180 if (!buffer_is_empty(s->compress_cache_dir)) { 181 mkdir_recursive(s->compress_cache_dir->ptr); 182 137 183 struct stat st; 138 184 if (0 != stat(s->compress_cache_dir->ptr, &st)) { 139 185 log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir", … … 342 388 BUFFER_APPEND_SLASH(p->ofn); 343 389 344 390 if (0 == strncmp(con->physical.path->ptr, con->physical.doc_root->ptr, con->physical.doc_root->used-1)) { 345 size_t offset = p->ofn->used - 1;346 char *dir, *nextdir;347 348 391 buffer_append_string(p->ofn, con->physical.path->ptr + con->physical.doc_root->used - 1); 349 350 392 buffer_copy_string_buffer(p->b, p->ofn); 351 352 /* mkdir -p ... */353 for (dir = p->b->ptr + offset; NULL != (nextdir = strchr(dir, '/')); dir = nextdir + 1) {354 *nextdir = '\0';355 356 if (-1 == mkdir(p->b->ptr, 0700)) {357 if (errno != EEXIST) {358 log_error_write(srv, __FILE__, __LINE__, "sbss", "creating cache-directory", p->b, "failed", strerror(errno));359 360 return -1;361 }362 }363 364 *nextdir = '/';365 }366 393 } else { 367 394 buffer_append_string_buffer(p->ofn, con->uri.path); 368 395 } … … 395 422 return 0; 396 423 } 397 424 398 log_error_write(srv, __FILE__, __LINE__, "sbss", "creating cachefile", p->ofn, "failed", strerror(errno)); 425 if (-1 == mkdir_for_file(p->ofn->ptr)) { 426 log_error_write(srv, __FILE__, __LINE__, "sb", "couldn't create directory for file", p->ofn); 427 return -1; 428 } 399 429 400 return -1; 430 if (-1 == (ofd = open(p->ofn->ptr, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))) { 431 log_error_write(srv, __FILE__, __LINE__, "sbss", "creating cachefile", p->ofn, "failed", strerror(errno)); 432 return -1; 433 } 401 434 } 402 435 #if 0 403 436 log_error_write(srv, __FILE__, __LINE__, "bs", p->ofn, "compress-cache miss");

