| 133 | } |
| 134 | |
| 135 | struct tmp_objdir *tmp_objdir_create(struct repository *r, |
| 136 | const char *prefix) |
| 137 | { |
| 138 | static int installed_handlers; |
| 139 | struct tmp_objdir *t; |
| 140 | |
| 141 | if (the_tmp_objdir) |
| 142 | BUG("only one tmp_objdir can be used at a time"); |
| 143 | |
| 144 | t = xcalloc(1, sizeof(*t)); |
| 145 | t->repo = r; |
| 146 | strbuf_init(&t->path, 0); |
| 147 | strvec_init(&t->env); |
| 148 | |
| 149 | /* |
| 150 | * Use a string starting with tmp_ so that the builtin/prune.c code |
| 151 | * can recognize any stale objdirs left behind by a crash and delete |
| 152 | * them. |
| 153 | */ |
| 154 | strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", |
| 155 | repo_get_object_directory(r), prefix); |
| 156 | |
| 157 | if (!is_absolute_path(t->path.buf)) |
| 158 | chdir_notify_register(NULL, tmp_objdir_reparent, t); |
| 159 | |
| 160 | if (!mkdtemp(t->path.buf)) { |
| 161 | /* free, not destroy, as we never touched the filesystem */ |
| 162 | tmp_objdir_free(t); |
| 163 | return NULL; |
| 164 | } |
| 165 | |
| 166 | the_tmp_objdir = t; |
| 167 | if (!installed_handlers) { |
| 168 | atexit(remove_tmp_objdir); |
| 169 | installed_handlers++; |
| 170 | } |
| 171 | |
| 172 | if (setup_tmp_objdir(t->path.buf)) { |
| 173 | tmp_objdir_destroy(t); |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | env_append(&t->env, ALTERNATE_DB_ENVIRONMENT, |
| 178 | absolute_path(repo_get_object_directory(r))); |
| 179 | env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf)); |
| 180 | env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT, |
| 181 | absolute_path(t->path.buf)); |
| 182 | |
| 183 | return t; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Make sure we copy packfiles and their associated metafiles in the correct |
no test coverage detected