static int rerere_forget_one_path(const char *path, struct string_list *rr) { const char *filename; char *hex; unsigned char sha1[20]; int ret; ret = handle_cache(path, sha1, NULL); if (ret < 1) return error("Could not parse conflict hunks in '%s'", path); hex = xstrdup(sha1_to_hex(sha1)); filename = rerere_path(hex, "postimage"); if (unlink(filename)) return (errno == ENOENT ? error("no remembered resolution for %s", path) : error("cannot unlink %s: %s", filename, strerror(errno))); handle_cache(path, sha1, rerere_path(hex, "preimage")); fprintf(stderr, "Updated preimage for '%s'\n", path); string_list_insert(rr, path)->util = hex; fprintf(stderr, "Forgot resolution for %s\n", path); return 0; }
static int rerere_forget_one_path(const char *path, struct string_list *rr) { const char *filename; struct rerere_id *id; unsigned char sha1[20]; int ret; struct string_list_item *item; /* * Recreate the original conflict from the stages in the * index and compute the conflict ID */ ret = handle_cache(path, sha1, NULL); if (ret < 1) return error("Could not parse conflict hunks in '%s'", path); /* Nuke the recorded resolution for the conflict */ id = new_rerere_id(sha1); filename = rerere_path(id, "postimage"); if (unlink(filename)) return (errno == ENOENT ? error("no remembered resolution for %s", path) : error("cannot unlink %s: %s", filename, strerror(errno))); /* * Update the preimage so that the user can resolve the * conflict in the working tree, run us again to record * the postimage. */ handle_cache(path, sha1, rerere_path(id, "preimage")); fprintf(stderr, "Updated preimage for '%s'\n", path); /* * And remember that we can record resolution for this * conflict when the user is done. */ item = string_list_insert(rr, path); free_rerere_id(item); item->util = id; fprintf(stderr, "Forgot resolution for %s\n", path); return 0; }
static int rerere_forget_one_path(const char *path, struct string_list *rr) { const char *filename; struct rerere_id *id; unsigned char sha1[20]; int ret; struct string_list_item *item; /* * Recreate the original conflict from the stages in the * index and compute the conflict ID */ ret = handle_cache(path, sha1, NULL); if (ret < 1) return error(_("could not parse conflict hunks in '%s'"), path); /* Nuke the recorded resolution for the conflict */ id = new_rerere_id(sha1); for (id->variant = 0; id->variant < id->collection->status_nr; id->variant++) { mmfile_t cur = { NULL, 0 }; mmbuffer_t result = {NULL, 0}; int cleanly_resolved; if (!has_rerere_resolution(id)) continue; handle_cache(path, sha1, rerere_path(id, "thisimage")); if (read_mmfile(&cur, rerere_path(id, "thisimage"))) { free(cur.ptr); error(_("failed to update conflicted state in '%s'"), path); goto fail_exit; } cleanly_resolved = !try_merge(id, path, &cur, &result); free(result.ptr); free(cur.ptr); if (cleanly_resolved) break; } if (id->collection->status_nr <= id->variant) { error(_("no remembered resolution for '%s'"), path); goto fail_exit; } filename = rerere_path(id, "postimage"); if (unlink(filename)) { if (errno == ENOENT) error(_("no remembered resolution for '%s'"), path); else error_errno(_("cannot unlink '%s'"), filename); goto fail_exit; } /* * Update the preimage so that the user can resolve the * conflict in the working tree, run us again to record * the postimage. */ handle_cache(path, sha1, rerere_path(id, "preimage")); fprintf_ln(stderr, _("Updated preimage for '%s'"), path); /* * And remember that we can record resolution for this * conflict when the user is done. */ item = string_list_insert(rr, path); free_rerere_id(item); item->util = id; fprintf(stderr, _("Forgot resolution for '%s'\n"), path); return 0; fail_exit: free(id); return -1; }
int static_file_handle(request_t *req, response_t *resp, handler_ctx_t *ctx) { mod_static_conf_t *conf; char path[2048]; int fd = -1, res, use_301; struct stat st; size_t len, pathlen, filesize, fileoffset; ctx_state_t val; conf = (mod_static_conf_t*) ctx->conf; len = strlen(conf->root); strncpy(path, conf->root, 2048); if (path[len - 1] == '/') { path[len - 1] = '\0'; } if (req->path[0] != '/') { return response_send_status(resp, STATUS_BAD_REQUEST); } strncat(path, req->path, 2048 - len); debug("Request path: %s, real file path: %s", req->path, path); res = try_open_file(path, &fd, &st); if (res < 0) { return static_file_handle_error(resp, fd); } else if (res > 0) { // Is a directory, try index files. pathlen = strlen(path); use_301 = 0; if (path[pathlen - 1] != '/') { path[pathlen] = '/'; path[pathlen + 1] = '\0'; pathlen++; use_301 = 1; } //for (i = 0; i < 10 && res != 0 && conf->index[i] != NULL; i++) { // path[pathlen] = '\0'; // strncat(path, conf->index[i], 2048 - pathlen); // res = try_open_file(path, &fd, &st); //} path[pathlen] = '\0'; strncat(path, conf->index, 2048 - pathlen); res = try_open_file(path, &fd, &st); path[pathlen] = '\0'; if (res != 0) { if (conf->enable_list_dir) { if (use_301) { // TODO Support HTTPS snprintf(path, 2048, "http://%s%s/", req->host, req->path); response_set_header(resp, "Location", path); resp->status = STATUS_MOVED; resp->content_length = 0; response_send_headers(resp, NULL); return HANDLER_DONE; } show_hidden_file = conf->show_hidden_file; return static_file_listdir(resp, req->path, path); } else { return static_file_handle_error(resp, fd); } } } fileoffset = 0; filesize = st.st_size; res = handle_range(req, resp, &fileoffset, &filesize); if (res < 0) { resp->status = STATUS_OK; } else if (res == 0) { resp->status = STATUS_PARTIAL_CONTENT; } else { return response_send_status(resp, STATUS_RANGE_NOT_SATISFIABLE); } resp->content_length = filesize; handle_content_type(resp, path); if (handle_cache(req, resp, &st, conf)) { return response_send_status(resp, STATUS_NOT_MODIFIED); } val.as_int = fd; context_push(ctx, val); val.as_long = fileoffset; context_push(ctx, val); val.as_long = filesize; context_push(ctx, val); debug("sending headers"); response_send_headers(resp, static_file_write_content); return HANDLER_UNFISHED; }