| 217 | } |
| 218 | |
| 219 | static cbm_store_t *cp_index_files(CP_Proj *lp, const CP_File *files, int nfiles) { |
| 220 | memset(lp, 0, sizeof(*lp)); |
| 221 | snprintf(lp->tmpdir, sizeof(lp->tmpdir), "/tmp/cbm_cp_XXXXXX"); |
| 222 | if (!cbm_mkdtemp(lp->tmpdir)) return NULL; |
| 223 | cp_to_fwd_slashes(lp->tmpdir); |
| 224 | for (int i = 0; i < nfiles; i++) { |
| 225 | char path[700]; |
| 226 | snprintf(path, sizeof(path), "%s/%s", lp->tmpdir, files[i].name); |
| 227 | char *slash = strrchr(path, '/'); |
| 228 | if (slash && slash > path + strlen(lp->tmpdir)) { |
| 229 | *slash = '\0'; |
| 230 | cbm_mkdir_p(path, 0755); |
| 231 | *slash = '/'; |
| 232 | } |
| 233 | FILE *f = fopen(path, "wb"); |
| 234 | if (!f) return NULL; |
| 235 | fputs(files[i].content, f); |
| 236 | fclose(f); |
| 237 | } |
| 238 | return cp_open_indexed(lp); |
| 239 | } |
| 240 | |
| 241 | static void cp_cleanup(CP_Proj *lp, cbm_store_t *store) { |
| 242 | if (store) cbm_store_close(store); |
no test coverage detected