Apophis.xs

filter: Statementstmt 98.7% 479 / 485 Branchbran 93.1% 241 / 262 (3 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 96.7% 720 / 747 (3 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/arch/Apophis/Install/Files.pm ↑ Summary blib/lib/Apophis.pm »
1 /*
2 * Apophis.xs - Content-addressable storage with deterministic UUID v5
3 *
4 * Named after Apophis, the Egyptian serpent of chaos — here tamed
5 * to bring order to content through deterministic hashing.
6 *
7 * 100% XS: all logic in C, Perl layer is just XSLoader.
8 * Uses Horus library for RFC 9562 UUID v5 (SHA-1 namespace) generation.
9 */
10  
11 #define PERL_NO_GET_CONTEXT
12 #include "EXTERN.h"
13 #include "perl.h"
14 #include "XSUB.h"
15  
16 #include "ppport.h"
17 #include "xop_compat.h"
18  
19 #include <sys/stat.h>
20 #include <errno.h>
21 #ifndef _WIN32
22 # include <unistd.h>
23 #else
24 # include <io.h>
25 # include <direct.h>
26 # include <windows.h> /* MoveFileEx; perl.h has it already, this is a guard */
27 #endif
28  
29 /*
30 * Windows compatibility:
31 * perl.h on threaded Windows redefines mkdir, stat, unlink etc. as macros
32 * requiring the interpreter context (my_perl). Our static C helper functions
33 * don't have pTHX, so we undo those overrides and use the real libc calls.
34 */
35 #ifdef WIN32
36 # undef mkdir
37 # undef stat
38 # undef unlink
39 # undef rename
40 # undef open
41 # undef close
42 # undef read
43 # undef write
44 /* Windows mkdir takes only one arg */
45 # define apophis_mkdir(p, m) _mkdir(p)
46 /*
47 * Stat_t is struct w32_stat, the layout perl's own stat() fills in - but
48 * that stat() is the macro undef'd just above, so what is left is the CRT
49 * one, which writes a differently shaped struct. Pair the call and the
50 * type instead: _stat64 keeps st_size 64 bit, which the CRT's struct stat
51 * does not on Win64.
52 */
53 # define apophis_stat_t struct _stat64
54 # define apophis_stat(p, b) _stat64((p), (b))
55 #else
56 # define apophis_mkdir(p, m) mkdir(p, m)
57 # define apophis_stat_t struct stat
58 # define apophis_stat(p, b) stat((p), (b))
59 #endif
60  
61 /*
62 * The CRT rename() refuses a destination that already exists, so the second
63 * store of the same content with metadata could not replace its sidecar.
64 * MoveFileEx replaces, and stays atomic.
65 */
66 static int
67 33 apophis_rename(const char *from, const char *to)
68 {
69 #ifdef WIN32
70 if (MoveFileExA(from, to, MOVEFILE_REPLACE_EXISTING))
71 return 0;
72 errno = EACCES;
73 return -1;
74 #else
75 33 return rename(from, to);
76 #endif
77 }
78  
79 /* Horus UUID library - pure C, no Perl deps */
80 #define HORUS_FATAL(msg) croak("%s", (msg))
81 #include "horus_core.h"
82  
83 /* ------------------------------------------------------------------ */
84 /* Constants */
85 /* ------------------------------------------------------------------ */
86  
87 #define APOPHIS_STREAM_BUF 65536 /* 64KB read chunks for streaming */
88 #define APOPHIS_PATH_MAX 4096
89  
90 /* ------------------------------------------------------------------ */
91 /* Internal: namespace UUID generation */
92 /* ------------------------------------------------------------------ */
93  
94 /* Derive a namespace UUID from a human-readable string via v5(DNS, name) */
95 static void
96 37 apophis_derive_namespace(unsigned char *ns_out,
97 const char *name, STRLEN name_len)
98 {
99 37 horus_uuid_v5(ns_out, HORUS_NS_DNS,
100 (const unsigned char *)name, (size_t)name_len);
101 37 }
102  
103 /* Format 16-byte UUID binary to 36-char string SV */
104 static SV *
105 38 apophis_uuid_to_sv(pTHX_ const unsigned char *uuid)
106 {
107 char buf[HORUS_FMT_STR_LEN + 1];
108 38 horus_format_uuid(buf, uuid, HORUS_FMT_STR);
109 38 return newSVpvn(buf, HORUS_FMT_STR_LEN);
110 }
111  
112 /* ------------------------------------------------------------------ */
113 /* Internal: content identification */
114 /* ------------------------------------------------------------------ */
115  
116 /* Identify in-memory content: v5(namespace, content) */
117 static void
118 75 apophis_identify_content(unsigned char *uuid_out,
119 const unsigned char *ns_bytes,
120 const char *content, STRLEN content_len)
121 {
122 75 horus_uuid_v5(uuid_out, ns_bytes,
123 (const unsigned char *)content, (size_t)content_len);
124 75 }
125  
126 /* Identify via streaming SHA-1 — O(1) memory */
127 static void
128 17 apophis_identify_stream(pTHX_ unsigned char *uuid_out,
129 const unsigned char *ns_bytes,
130 PerlIO *fh)
131 {
132 horus_sha1_ctx ctx;
133 unsigned char buf[APOPHIS_STREAM_BUF];
134 unsigned char digest[20];
135 SSize_t nread;
136  
137 17 horus_sha1_init(&ctx);
138 17 horus_sha1_update(&ctx, ns_bytes, 16); /* namespace first per RFC */
139  
140 37 ▶ while ((nread = PerlIO_read(fh, buf, sizeof(buf))) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while ((nread = PerlIO_read(fh, buf, sizeof(buf))) > 0) { 20 17 37
141 20 horus_sha1_update(&ctx, (const unsigned char *)buf, (size_t)nread);
142 }
143  
144 17 horus_sha1_final(digest, &ctx);
145 17 memcpy(uuid_out, digest, 16);
146 17 horus_stamp_version_variant(uuid_out, 5);
147 17 }
148  
149 /* ------------------------------------------------------------------ */
150 /* Internal: path computation */
151 /* ------------------------------------------------------------------ */
152  
153 /* Build 2-level sharded path: store_dir/a3/bb/a3bb189e-...-1e3a
154 * Returns length written (excluding NUL). */
155 static int
156 134 apophis_build_path(char *out, size_t out_size,
157 const char *store_dir, STRLEN store_len,
158 const char *id, STRLEN id_len)
159 {
160 /* UUID is 36 chars: a3bb189e-8bf9-5f18-b3f6-1b2f5f5c1e3a
161 * Shard on first 2 and chars 3-4 (skipping no hyphens needed,
162 * first 4 hex chars are positions 0-3 of the UUID string) */
163 134 ▶ if (id_len < 5)
Branch: 1 branch
BranchTrueFalseTotal
if (id_len < 5) 1 133 134
164 1 croak("Apophis: invalid UUID id");
165  
166 266 return snprintf(out, out_size, "%.*s/%c%c/%c%c/%.*s",
167 (int)store_len, store_dir,
168 133 id[0], id[1], /* first shard level */
169 133 id[2], id[3], /* second shard level */
170 (int)id_len, id);
171 }
172  
173 /* The same for the XSUBs, which have nowhere to report a truncated path: a
174 * path that does not fit, with room left for the .tmp.<pid> and .meta
175 * suffixes written beside it, is a different file, so it croaks. */
176 #define APOPHIS_PATH_ROOM 24
177  
178 static int
179 129 apophis_path(char *out, size_t out_size,
180 const char *store_dir, STRLEN store_len,
181 const char *id, STRLEN id_len)
182 {
183 129 int len = apophis_build_path(out, out_size, store_dir, store_len, id, id_len);
184 128 ▶ if (len < 0 || (size_t)len + APOPHIS_PATH_ROOM >= out_size) /* # uncoverable condition left count:1 */
Branch: 2 branches
BranchTrueFalseTotal
if (len < 0 || (size_t)len + APOPHIS_PATH_ROOM >= out_size) /* # uncoverable condition left count:1 */ 128 0 128
if (len < 0 || (size_t)len + APOPHIS_PATH_ROOM >= out_size) /* # uncoverable condition left count:1 */ 1 127 128
185 1 croak("Apophis: path too long");
186 127 return len;
187 }
188  
189 /* Build path for .meta sidecar */
190 static int
191 23 apophis_build_meta_path(char *out, size_t out_size,
192 const char *content_path, int content_path_len)
193 {
194 23 return snprintf(out, out_size, "%.*s.meta",
195 content_path_len, content_path);
196 }
197  
198 /* ------------------------------------------------------------------ */
199 /* Internal: recursive mkdir */
200 /* ------------------------------------------------------------------ */
201  
202 static void
203 33 apophis_mkdir_p(const char *path)
204 {
205 char buf[APOPHIS_PATH_MAX];
206 char *p;
207 size_t len;
208  
209 33 len = strlen(path);
210 33 memcpy(buf, path, len + 1);
211  
212 730 ▶ for (p = buf + 1; *p; p++) {
Branch: 1 branch
BranchTrueFalseTotal
for (p = buf + 1; *p; p++) { 698 32 730
213 698 ▶ if (*p == '/') {
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '/') { 106 592 698
214 106 *p = '\0';
215 106 ▶ if (apophis_mkdir(buf, 0777) != 0 && errno != EEXIST) {
Branch: 2 branches
BranchTrueFalseTotal
if (apophis_mkdir(buf, 0777) != 0 && errno != EEXIST) { 79 27 106
if (apophis_mkdir(buf, 0777) != 0 && errno != EEXIST) { 1 78 79
216 1 croak("Apophis: cannot create directory '%s': %s",
217 buf, strerror(errno));
218 }
219 105 *p = '/';
220 }
221 }
222 /* Final component */
223 32 ▶ if (apophis_mkdir(buf, 0777) != 0 && errno != EEXIST) {
Branch: 2 branches
BranchTrueFalseTotal
if (apophis_mkdir(buf, 0777) != 0 && errno != EEXIST) { 7 25 32
if (apophis_mkdir(buf, 0777) != 0 && errno != EEXIST) { 1 6 7
224 1 croak("Apophis: cannot create directory '%s': %s",
225 buf, strerror(errno));
226 }
227 31 }
228  
229 /* Ensure parent directory of a file path exists */
230 static void
231 35 apophis_ensure_parent_dir(const char *file_path)
232 {
233 char buf[APOPHIS_PATH_MAX];
234 char *last_slash;
235 size_t len;
236  
237 35 len = strlen(file_path);
238 35 ▶ if (len >= sizeof(buf))
Branch: 1 branch
BranchTrueFalseTotal
if (len >= sizeof(buf)) 1 34 35
239 1 croak("Apophis: path too long");
240  
241 34 memcpy(buf, file_path, len + 1);
242 34 last_slash = strrchr(buf, '/');
243 34 ▶ if (last_slash) {
Branch: 1 branch
BranchTrueFalseTotal
if (last_slash) { 33 1 34
244 33 *last_slash = '\0';
245 33 apophis_mkdir_p(buf);
246 }
247 32 }
248  
249 /* ------------------------------------------------------------------ */
250 /* Internal: atomic file write (temp + rename) */
251 /* ------------------------------------------------------------------ */
252  
253 static void
254 32 apophis_atomic_write(pTHX_ const char *path,
255 const char *content, STRLEN content_len)
256 {
257 char tmp_path[APOPHIS_PATH_MAX];
258 PerlIO *fh;
259 SSize_t written;
260  
261 32 snprintf(tmp_path, sizeof(tmp_path), "%s.tmp.%d",
262 32 path, (int)getpid());
263  
264 32 fh = PerlIO_open(tmp_path, "wb");
265 32 ▶ if (!fh)
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) 1 31 32
266 1 croak("Apophis: cannot write '%s': %s", tmp_path, strerror(errno));
267  
268 31 written = PerlIO_write(fh, content, content_len);
269 31 PerlIO_close(fh);
270  
271 /*
272 # uncoverable branch true
273 # uncoverable condition left count:1 */
274 31 ▶ if (written != (SSize_t)content_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (written != (SSize_t)content_len) { 0 31 31
275 0 unlink(tmp_path); /* # uncoverable statement */
276 0 croak("Apophis: short write to '%s'", tmp_path); /* # uncoverable statement */
277 }
278  
279 31 ▶ if (apophis_rename(tmp_path, path) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_rename(tmp_path, path) != 0) { 1 30 31
280 1 unlink(tmp_path);
281 1 croak("Apophis: cannot rename '%s' -> '%s': %s",
282 tmp_path, path, strerror(errno));
283 }
284 30 }
285  
286 /* ------------------------------------------------------------------ */
287 /* Internal: metadata sidecar (key=value\n format) */
288 /* ------------------------------------------------------------------ */
289  
290 static void
291 3 apophis_meta_write(pTHX_ const char *meta_path, HV *meta)
292 {
293 PerlIO *fh;
294 HE *entry;
295 char tmp_path[APOPHIS_PATH_MAX];
296  
297 3 snprintf(tmp_path, sizeof(tmp_path), "%s.tmp.%d",
298 3 meta_path, (int)getpid());
299  
300 3 fh = PerlIO_open(tmp_path, "w");
301 3 ▶ if (!fh)
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) 1 2 3
302 1 croak("Apophis: cannot write metadata '%s': %s",
303 tmp_path, strerror(errno));
304  
305 2 hv_iterinit(meta);
306 5 ▶ while ((entry = hv_iternext(meta))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((entry = hv_iternext(meta))) { 3 2 5
307 3 SV *val = hv_iterval(meta, entry);
308 I32 klen;
309 3 const char *key = hv_iterkey(entry, &klen);
310 STRLEN vlen;
311 3 const char *vstr = SvPV(val, vlen);
312 3 PerlIO_write(fh, key, (SSize_t)klen);
313 3 PerlIO_write(fh, "=", 1);
314 3 PerlIO_write(fh, vstr, (SSize_t)vlen);
315 3 PerlIO_write(fh, "\n", 1);
316 }
317  
318 2 PerlIO_close(fh);
319  
320 2 ▶ if (apophis_rename(tmp_path, meta_path) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_rename(tmp_path, meta_path) != 0) { 1 1 2
321 1 unlink(tmp_path);
322 1 croak("Apophis: cannot rename metadata '%s': %s",
323 tmp_path, strerror(errno));
324 }
325 1 }
326  
327 static HV *
328 9 apophis_meta_read(pTHX_ const char *meta_path)
329 {
330 PerlIO *fh;
331 HV *meta;
332 apophis_stat_t st;
333 char *buf, *p, *end;
334 SSize_t nread;
335  
336 9 ▶ if (apophis_stat(meta_path, &st) != 0) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_stat(meta_path, &st) != 0) return NULL; 5 4 9
337  
338 4 fh = PerlIO_open(meta_path, "r");
339 4 ▶ if (!fh) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) return NULL; 1 3 4
340  
341 3 buf = (char *)malloc((size_t)st.st_size + 1);
342 /*
343 # uncoverable branch true
344 # uncoverable condition left count:1 */
345 3 ▶ if (!buf) { PerlIO_close(fh); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) { PerlIO_close(fh); return NULL; } 0 3 3
346  
347 3 nread = PerlIO_read(fh, buf, (Size_t)st.st_size);
348 3 ▶ if (PerlIO_error(fh)) nread = -1;
Branch: 1 branch
BranchTrueFalseTotal
if (PerlIO_error(fh)) nread = -1; 0 3 3
349 3 PerlIO_close(fh);
350  
351 3 ▶ if (nread < 0) { free(buf); return NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (nread < 0) { free(buf); return NULL; } 0 3 3
352 3 buf[nread] = '\0';
353  
354 3 meta = newHV();
355 3 p = buf;
356 3 end = buf + nread;
357  
358 8 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 5 3 8
359 5 char *line_end = strchr(p, '\n');
360 char *eq;
361 5 ▶ if (!line_end) line_end = end;
Branch: 1 branch
BranchTrueFalseTotal
if (!line_end) line_end = end; 1 4 5
362  
363 5 eq = (char *)memchr(p, '=', (size_t)(line_end - p));
364 5 ▶ if (eq) {
Branch: 1 branch
BranchTrueFalseTotal
if (eq) { 4 1 5
365 4 hv_store(meta, p, (I32)(eq - p),
366 newSVpvn(eq + 1, (STRLEN)(line_end - eq - 1)), 0);
367 }
368  
369 5 p = line_end + 1;
370 }
371  
372 3 free(buf);
373 3 return meta;
374 }
375  
376 /* ------------------------------------------------------------------ */
377 /* Internal: object field accessors */
378 /* ------------------------------------------------------------------ */
379  
380 /* Get the 16-byte namespace bytes from the object */
381 static const unsigned char *
382 100 apophis_get_ns(pTHX_ HV *self)
383 {
384 100 SV **svp = hv_fetchs(self, "_ns_bytes", 0);
385 100 ▶ if (!svp || !SvOK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) 99 1 100
if (!svp || !SvOK(*svp)) 1 98 99
386 2 croak("Apophis: object has no namespace (not properly constructed)");
387 196 return (const unsigned char *)SvPV_nolen(*svp);
388 }
389  
390 /* Get store_dir from object, or from opts, or croak */
391 static const char *
392 128 apophis_get_store_dir(pTHX_ HV *self, HV *opts, STRLEN *len_out)
393 {
394 SV **svp;
395  
396 /* Check opts first */
397 128 ▶ if (opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (opts) { 20 108 128
398 20 svp = hv_fetchs(opts, "store_dir", 0);
399 20 ▶ if (svp && SvOK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) 14 6 20
if (svp && SvOK(*svp)) 13 1 14
400 26 return SvPV(*svp, *len_out);
401 }
402  
403 /* Fall back to object */
404 115 svp = hv_fetchs(self, "store_dir", 0);
405 115 ▶ if (svp && SvOK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) 112 3 115
if (svp && SvOK(*svp)) 111 1 112
406 222 return SvPV(*svp, *len_out);
407  
408 4 croak("Apophis: no store_dir specified");
409 return NULL; /* not reached */
410 }
411  
412  
413 /* ================================================================== */
414 /* The six fused bodies */
415 /* */
416 /* identify, store, exists, fetch, verify and remove each have one */
417 /* body here. The XSUB of that name runs it, and so does the custom op */
418 /* a call to it compiles to under `use Apophis`. `who` is the name a */
419 /* croak reports. `args` and `items` are the XSUB's stack, for the */
420 /* key/value options after the positional arguments; the op passes */
421 /* NULL and 2, since it only stands for a call with none. */
422 /* ================================================================== */
423  
424 static HV *
425 158 apophis_self_hv(pTHX_ const char *who, SV *self)
426 {
427 158 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 13 145 158
428 13 croak("%s: not an object", who);
429 145 return (HV *)SvRV(self);
430 }
431  
432 /* The trailing key/value pairs as a mortal HV, or NULL when there are
433 * none. When `meta` is given, a `meta` hashref goes there instead. */
434 static HV *
435 107 apophis_opts(pTHX_ const char *who, SV **args, I32 items, HV **meta)
436 {
437 HV *opts;
438 I32 i;
439  
440 107 ▶ if (items <= 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items <= 2) 84 23 107
441 84 return NULL;
442 23 ▶ if ((items - 2) % 2 != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 2) % 2 != 0) 7 16 23
443 7 croak("%s: odd number of optional arguments", who);
444 16 opts = (HV *)sv_2mortal((SV *)newHV());
445 32 ▶ for (i = 2; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i += 2) { 16 16 32
446 STRLEN klen;
447 16 const char *k = SvPV(args[i], klen);
448 16 SV *v = args[i + 1];
449 16 ▶ if (meta && strEQ(k, "meta") && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV)
Branch: 4 branches
BranchTrueFalseTotal
if (meta && strEQ(k, "meta") && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) 8 8 16
if (meta && strEQ(k, "meta") && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) 6 2 8
if (meta && strEQ(k, "meta") && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) 5 1 6
if (meta && strEQ(k, "meta") && SvROK(v) && SvTYPE(SvRV(v)) == SVt_PVHV) 3 2 5
450 3 *meta = (HV *)SvRV(v);
451 else
452 13 (void)hv_store(opts, k, klen, SvREFCNT_inc(v), 0);
453 }
454 16 return opts;
455 }
456  
457 static const char *
458 71 apophis_content_of(pTHX_ const char *who, SV *content_ref, STRLEN *len)
459 {
460 71 ▶ if (!SvROK(content_ref))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(content_ref)) 6 65 71
461 6 croak("%s: argument must be a scalar reference", who);
462 130 return SvPV(SvRV(content_ref), *len);
463 }
464  
465 static void
466 39 apophis_do_identify(pTHX_ const char *who, SV *self, SV *content_ref, unsigned char *uuid)
467 {
468 39 HV *hv = apophis_self_hv(aTHX_ who, self);
469 36 const unsigned char *ns = apophis_get_ns(aTHX_ hv);
470 STRLEN content_len;
471 34 const char *content = apophis_content_of(aTHX_ who, content_ref, &content_len);
472  
473 30 apophis_identify_content(uuid, ns, content, content_len);
474 30 }
475  
476 /* Writes the id, HORUS_FMT_STR_LEN bytes and a NUL, into id_str. */
477 static void
478 39 apophis_do_store(pTHX_ const char *who, SV *self, SV *content_ref, SV **args, I32 items, char *id_str)
479 {
480 39 HV *hv = apophis_self_hv(aTHX_ who, self);
481 37 const unsigned char *ns = apophis_get_ns(aTHX_ hv);
482 STRLEN content_len, store_dir_len;
483 37 const char *content = apophis_content_of(aTHX_ who, content_ref, &content_len);
484 35 HV *meta = NULL;
485 35 HV *opts = apophis_opts(aTHX_ who, args, items, &meta);
486 const char *store_dir;
487 unsigned char uuid[16];
488 char path[APOPHIS_PATH_MAX];
489 int path_len;
490 apophis_stat_t st;
491  
492 33 apophis_identify_content(uuid, ns, content, content_len);
493 33 horus_format_uuid(id_str, uuid, HORUS_FMT_STR);
494  
495 33 store_dir = apophis_get_store_dir(aTHX_ hv, opts, &store_dir_len);
496 33 path_len = apophis_path(path, sizeof(path), store_dir, store_dir_len, id_str, HORUS_FMT_STR_LEN);
497  
498 32 ▶ if (apophis_stat(path, &st) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_stat(path, &st) != 0) { 23 9 32
499 23 apophis_ensure_parent_dir(path);
500 21 apophis_atomic_write(aTHX_ path, content, content_len);
501 }
502  
503 29 ▶ if (meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (meta) { 3 26 29
504 char meta_path[APOPHIS_PATH_MAX];
505 3 apophis_build_meta_path(meta_path, sizeof(meta_path), path, path_len);
506 3 apophis_meta_write(aTHX_ meta_path, meta);
507 }
508 27 }
509  
510 /* The sharded path of an id under the store, for the four methods that
511 * take an id and options. Gives the id's bytes back for verify. */
512 static int
513 72 apophis_id_path(pTHX_ const char *who, HV *hv, SV *id, SV **args, I32 items,
514 char *path, size_t path_size, const char **id_str, STRLEN *id_len)
515 {
516 72 HV *opts = apophis_opts(aTHX_ who, args, items, NULL);
517 STRLEN store_dir_len;
518 67 const char *store_dir = apophis_get_store_dir(aTHX_ hv, opts, &store_dir_len);
519  
520 63 *id_str = SvPV(id, *id_len);
521 63 return apophis_path(path, path_size, store_dir, store_dir_len, *id_str, *id_len);
522 }
523  
524 static bool
525 28 apophis_do_exists(pTHX_ const char *who, SV *self, SV *id, SV **args, I32 items)
526 {
527 const char *id_str;
528 STRLEN id_len;
529 char path[APOPHIS_PATH_MAX];
530 apophis_stat_t st;
531  
532 28 apophis_id_path(aTHX_ who, apophis_self_hv(aTHX_ who, self), id, args, items, path, sizeof(path), &id_str, &id_len);
533 20 return apophis_stat(path, &st) == 0;
534 }
535  
536 /* A new reference to the content, or &PL_sv_undef when there is none. */
537 static SV *
538 23 apophis_do_fetch(pTHX_ const char *who, SV *self, SV *id, SV **args, I32 items)
539 {
540 const char *id_str;
541 STRLEN id_len;
542 char path[APOPHIS_PATH_MAX];
543 apophis_stat_t st;
544 PerlIO *fh;
545 SV *content;
546 SSize_t nread;
547  
548 23 apophis_id_path(aTHX_ who, apophis_self_hv(aTHX_ who, self), id, args, items, path, sizeof(path), &id_str, &id_len);
549 20 ▶ if (apophis_stat(path, &st) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_stat(path, &st) != 0) 3 17 20
550 3 return &PL_sv_undef;
551  
552 17 fh = PerlIO_open(path, "rb");
553 17 ▶ if (!fh)
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) 2 15 17
554 2 croak("%s: cannot open '%s': %s", who, path, strerror(errno));
555  
556 15 content = newSV((STRLEN)st.st_size + 1);
557 15 SvPOK_on(content);
558 15 nread = PerlIO_read(fh, SvPVX(content), (Size_t)st.st_size);
559 15 ▶ if (PerlIO_error(fh))
Branch: 1 branch
BranchTrueFalseTotal
if (PerlIO_error(fh)) 0 15 15
560 0 nread = -1;
561 15 PerlIO_close(fh);
562  
563 15 ▶ if (nread < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (nread < 0) { 0 15 15
564 0 SvREFCNT_dec(content);
565 0 croak("%s: read error on '%s'", who, path);
566 }
567 15 SvCUR_set(content, (STRLEN)nread);
568 15 *SvEND(content) = '\0';
569 15 return newRV_noinc(content);
570 }
571  
572 static bool
573 15 apophis_do_verify(pTHX_ const char *who, SV *self, SV *id, SV **args, I32 items)
574 {
575 const char *id_str;
576 STRLEN id_len;
577 char path[APOPHIS_PATH_MAX];
578 PerlIO *fh;
579 unsigned char uuid[16];
580 char recomputed[HORUS_FMT_STR_LEN + 1];
581 15 HV *hv = apophis_self_hv(aTHX_ who, self);
582 13 const unsigned char *ns = apophis_get_ns(aTHX_ hv);
583  
584 13 apophis_id_path(aTHX_ who, hv, id, args, items, path, sizeof(path), &id_str, &id_len);
585 12 fh = PerlIO_open(path, "rb");
586 12 ▶ if (!fh)
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) 3 9 12
587 3 return FALSE;
588  
589 9 apophis_identify_stream(aTHX_ uuid, ns, fh);
590 9 PerlIO_close(fh);
591 9 horus_format_uuid(recomputed, uuid, HORUS_FMT_STR);
592 9 ▶ return id_len == HORUS_FMT_STR_LEN && memcmp(id_str, recomputed, HORUS_FMT_STR_LEN) == 0;
Branch: 2 branches
BranchTrueFalseTotal
return id_len == HORUS_FMT_STR_LEN && memcmp(id_str, recomputed, HORUS_FMT_STR_LEN) == 0; 8 1 9
return id_len == HORUS_FMT_STR_LEN && memcmp(id_str, recomputed, HORUS_FMT_STR_LEN) == 0; 6 2 8
593 }
594  
595 static bool
596 14 apophis_do_remove(pTHX_ const char *who, SV *self, SV *id, SV **args, I32 items)
597 {
598 const char *id_str;
599 STRLEN id_len;
600 char path[APOPHIS_PATH_MAX];
601 char meta_path[APOPHIS_PATH_MAX];
602 int path_len, removed;
603  
604 14 path_len = apophis_id_path(aTHX_ who, apophis_self_hv(aTHX_ who, self), id, args, items, path, sizeof(path), &id_str, &id_len);
605 11 removed = unlink(path) == 0;
606  
607 /* The sidecar goes too. It need not be there. */
608 11 apophis_build_meta_path(meta_path, sizeof(meta_path), path, path_len);
609 11 unlink(meta_path);
610 11 return removed ? TRUE : FALSE;
611 }
612  
613  
614 /* ================================================================== */
615 /* Custom ops */
616 /* */
617 /* Under `use Apophis`, a call to one of the six methods above with */
618 /* exactly its arguments compiles to a custom op in place of the */
619 /* entersub. The op keeps entersub's kids, so the method is still */
620 /* looked up at run time and the invocant decides. When it resolves */
621 /* to this module's own XSUB, the op runs the body straight off the */
622 /* stack: no sub call, no @_, and a result written into the pad slot */
623 /* the call site owns. Anything else, a method a subclass overrode, a */
624 /* wrapped sub, a call that turns out to carry options, runs */
625 /* pp_entersub itself, so it behaves exactly as it would have. */
626 /* ================================================================== */
627  
628 #define AP_HINT_KEY "Apophis/ops"
629  
630 enum { AP_IDENTIFY, AP_STORE, AP_EXISTS, AP_FETCH, AP_VERIFY, AP_REMOVE, AP_NOPS };
631  
632 static OP *pp_apophis_identify(pTHX);
633 static OP *pp_apophis_store(pTHX);
634 static OP *pp_apophis_exists(pTHX);
635 static OP *pp_apophis_fetch(pTHX);
636 static OP *pp_apophis_verify(pTHX);
637 static OP *pp_apophis_remove(pTHX);
638  
639 typedef struct {
640 const char *name;
641 STRLEN len;
642 int which;
643 } ap_name_t;
644  
645 /* The method names a call site may use, and the op each stands for. The
646 * op_ names are the aliases below, kept from when they were the only way
647 * to the fused bodies. */
648 static const ap_name_t ap_names[] = {
649 { "identify", 8, AP_IDENTIFY }, { "op_identify", 11, AP_IDENTIFY },
650 { "store", 5, AP_STORE }, { "op_store", 8, AP_STORE },
651 { "exists", 6, AP_EXISTS }, { "op_exists", 9, AP_EXISTS },
652 { "fetch", 5, AP_FETCH }, { "op_fetch", 8, AP_FETCH },
653 { "verify", 6, AP_VERIFY }, { "op_verify", 9, AP_VERIFY },
654 { "remove", 6, AP_REMOVE }, { "op_remove", 9, AP_REMOVE },
655 };
656  
657 static const char *const ap_method[AP_NOPS] = {
658 "identify", "store", "exists", "fetch", "verify", "remove",
659 };
660  
661 /* The name a croak reports, by op and by whether the call used the op_
662 * alias, which is the XSUB's ix. */
663 static const char *const ap_who[AP_NOPS][2] = {
664 { "Apophis::identify", "Apophis::op_identify" },
665 { "Apophis::store", "Apophis::op_store" },
666 { "Apophis::exists", "Apophis::op_exists" },
667 { "Apophis::fetch", "Apophis::op_fetch" },
668 { "Apophis::verify", "Apophis::op_verify" },
669 { "Apophis::remove", "Apophis::op_remove" },
670 };
671  
672 static OP *(*const ap_pp[AP_NOPS])(pTHX) = {
673 pp_apophis_identify, pp_apophis_store, pp_apophis_exists,
674 pp_apophis_fetch, pp_apophis_verify, pp_apophis_remove,
675 };
676  
677 static const char *const ap_xop_name[AP_NOPS] = {
678 "apophis_identify", "apophis_store", "apophis_exists",
679 "apophis_fetch", "apophis_verify", "apophis_remove",
680 };
681  
682 static const char *const ap_xop_desc[AP_NOPS] = {
683 "Apophis fused identify (SHA-1, UUID v5)",
684 "Apophis fused store (identify, mkdir, atomic write)",
685 "Apophis fused exists (path, stat)",
686 "Apophis fused fetch (path, stat, read)",
687 "Apophis fused verify (read, re-hash, compare)",
688 "Apophis fused remove (path, unlink, sidecar)",
689 };
690  
691 /* The C function behind each method's XSUB, taken at boot. A CV on the
692 * stack is ours when it runs one of these, which holds in every thread
693 * and survives nothing but a redefinition. */
694 static XSUBADDR_t ap_xsub[AP_NOPS];
695 static XOP ap_xop[AP_NOPS];
696  
697 static bool
698 13601 ap_ops_in_scope(pTHX)
699 {
700 13601 SV **ent = hv_fetchs(GvHV(PL_hintgv), AP_HINT_KEY, 0);
701 13601 ▶ return ent && SvTRUE(*ent);
Branch: 2 branches
BranchTrueFalseTotal
return ent && SvTRUE(*ent); 548 13053 13601
return ent && SvTRUE(*ent); 547 1 548
702 }
703  
704 /* entersub's own check has run. A method call to one of the names, with
705 * no more kids than the invocant and the one argument, becomes the op. */
706 static Perl_check_t ap_next_ck_entersub;
707  
708 static OP *
709 21791 ap_ck_entersub(pTHX_ OP *o)
710 {
711 21791 OP *kid, *last = NULL;
712 SV *meth;
713 const char *name;
714 STRLEN len;
715 21791 int nkids = 0;
716 size_t i;
717  
718 21791 o = ap_next_ck_entersub(aTHX_ o);
719 21791 ▶ if (o->op_type != OP_ENTERSUB
Branch: 1 branch
BranchTrueFalseTotal
if (o->op_type != OP_ENTERSUB 21531 260 21791
720 21531 ▶ || (o->op_private & (OPpENTERSUB_AMPER | OPpENTERSUB_DB))
Branch: 1 branch
BranchTrueFalseTotal
|| (o->op_private & (OPpENTERSUB_AMPER | OPpENTERSUB_DB)) 13601 7930 21531
721 13601 ▶ || !ap_ops_in_scope(aTHX))
Branch: 1 branch
BranchTrueFalseTotal
|| !ap_ops_in_scope(aTHX)) 13054 547 13601
722 21244 return o;
723  
724 /* The kids, or the nulled list that holds them, as ck_subr reads them. */
725 547 kid = cUNOPo->op_first;
726 547 ▶ if (!OpHAS_SIBLING(kid))
Branch: 1 branch
BranchTrueFalseTotal
if (!OpHAS_SIBLING(kid)) 328 219 547
727 328 kid = cUNOPx(kid)->op_first;
728 2933 ▶ for (; kid; kid = OpSIBLING(kid)) {
Branch: 1 branch
BranchTrueFalseTotal
for (; kid; kid = OpSIBLING(kid)) { 2386 547 2933
729 2386 last = kid;
730 2386 ▶ nkids++;
Branch: 1 branch
BranchTrueFalseTotal
nkids++; 1839 547 2386
731 }
732 /* pushmark, the invocant, the argument, the method */
733 547 ▶ if (last->op_type != OP_METHOD_NAMED || nkids > 4)
Branch: 2 branches
BranchTrueFalseTotal
if (last->op_type != OP_METHOD_NAMED || nkids > 4) 213 334 547
if (last->op_type != OP_METHOD_NAMED || nkids > 4) 65 148 213
734 399 return o;
735  
736 #if PERL_VERSION_GE(5,22,0)
737 148 meth = cMETHOPx_meth(last);
738 #else
739 meth = cSVOPx_sv(last);
740 #endif
741 148 name = SvPV(meth, len);
742 1127 ▶ for (i = 0; i < sizeof(ap_names) / sizeof(*ap_names); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < sizeof(ap_names) / sizeof(*ap_names); i++) { 1076 51 1127
743 1076 ▶ if (len == ap_names[i].len && memEQ(name, ap_names[i].name, len)) {
Branch: 2 branches
BranchTrueFalseTotal
if (len == ap_names[i].len && memEQ(name, ap_names[i].name, len)) { 208 868 1076
if (len == ap_names[i].len && memEQ(name, ap_names[i].name, len)) { 97 111 208
744 97 o->op_type = OP_CUSTOM;
745 97 o->op_ppaddr = ap_pp[ap_names[i].which];
746 #if PERL_VERSION_GE(5,16,0)
747 /* A perl that gives entersub a pad slot of its own, as 5.40
748 * and 5.42 do, never reaches the allocation.
749 # uncoverable branch true
750 # uncoverable condition left count:1 */
751 97 ▶ if (!o->op_targ)
Branch: 1 branch
BranchTrueFalseTotal
if (!o->op_targ) 0 97 97
752 0 o->op_targ = pad_alloc(OP_ENTERSUB, SVs_PADTMP); /* # uncoverable statement */
753 #endif
754 97 break;
755 }
756 }
757 148 return o;
758 }
759  
760 /* Above the mark sit the invocant, the argument and the CV the method
761 * resolved to. The op takes the call when that CV is the XSUB it stands
762 * for, and then only. */
763 static bool
764 117 ap_op_mine(pTHX_ SV **mark, SV **sp, int which)
765 {
766 117 SV *cv = *sp;
767 117 return sp - mark == 3
768 115 ▶ && SvTYPE(cv) == SVt_PVCV
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(cv) == SVt_PVCV 115 0 115
769 115 ▶ && CvISXSUB((CV *)cv)
Branch: 1 branch
BranchTrueFalseTotal
&& CvISXSUB((CV *)cv) 113 2 115
770 232 ▶ && CvXSUB((CV *)cv) == ap_xsub[which];
Branch: 2 branches
BranchTrueFalseTotal
&& CvXSUB((CV *)cv) == ap_xsub[which]; 115 2 117
&& CvXSUB((CV *)cv) == ap_xsub[which]; 113 0 113
771 }
772  
773 static const char *
774 113 ap_op_who(SV *cv, int which)
775 {
776 113 return ap_who[which][CvXSUBANY((CV *)cv).any_i32 ? 1 : 0];
777 }
778  
779 /* The call site's pad slot, which the check above saw to. */
780 static SV *
781 48 ap_op_targ(pTHX)
782 {
783 48 return PAD_SV(PL_op->op_targ);
784 }
785  
786 /* The call is over. Its three values go, and the result takes their
787 * place unless nothing wanted one. */
788 static OP *
789 99 ap_op_leave(pTHX_ I32 markix, SV *result)
790 {
791 99 dSP;
792 99 const I32 gimme = GIMME_V;
793  
794 99 SP = PL_stack_base + markix;
795 99 ▶ if (gimme != G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (gimme != G_VOID) 95 4 99
796 95 *++SP = result;
797 99 PUTBACK;
798 99 return NORMAL;
799 }
800  
801 /* The mark is kept as an index: a body may read a tied or overloaded
802 * argument, and that can move the stack. */
803 #define AP_OP_PROLOGUE(which) \
804 dSP; \
805 const I32 markix = TOPMARK; \
806 SV **mark = PL_stack_base + markix; \
807 const char *who; \
808 if (!ap_op_mine(aTHX_ mark, SP, (which))) \
809 return PL_ppaddr[OP_ENTERSUB](aTHX); \
810 who = ap_op_who(*SP, (which)); \
811 (void)POPMARK
812  
813 static OP *
814 33 pp_apophis_identify(pTHX)
815 {
816 unsigned char uuid[16];
817 char buf[HORUS_FMT_STR_LEN + 1];
818 SV *result;
819 33 ▶ AP_OP_PROLOGUE(AP_IDENTIFY);
Branch: 1 branch
BranchTrueFalseTotal
AP_OP_PROLOGUE(AP_IDENTIFY); 0 33 33
820  
821 33 apophis_do_identify(aTHX_ who, mark[1], mark[2], uuid);
822 28 horus_format_uuid(buf, uuid, HORUS_FMT_STR);
823 28 result = ap_op_targ(aTHX);
824 28 sv_setpvn(result, buf, HORUS_FMT_STR_LEN);
825 28 return ap_op_leave(aTHX_ markix, result);
826 }
827  
828 static OP *
829 25 pp_apophis_store(pTHX)
830 {
831 char id_str[HORUS_FMT_STR_LEN + 1];
832 SV *result;
833 25 ▶ AP_OP_PROLOGUE(AP_STORE);
Branch: 1 branch
BranchTrueFalseTotal
AP_OP_PROLOGUE(AP_STORE); 1 24 25
834  
835 24 apophis_do_store(aTHX_ who, mark[1], mark[2], NULL, 2, id_str);
836 20 result = ap_op_targ(aTHX);
837 20 sv_setpvn(result, id_str, HORUS_FMT_STR_LEN);
838 20 return ap_op_leave(aTHX_ markix, result);
839 }
840  
841 static OP *
842 22 pp_apophis_exists(pTHX)
843 {
844 22 ▶ AP_OP_PROLOGUE(AP_EXISTS);
Branch: 1 branch
BranchTrueFalseTotal
AP_OP_PROLOGUE(AP_EXISTS); 3 19 22
845 16 ▶ return ap_op_leave(aTHX_ markix,
Branch: 1 branch
BranchTrueFalseTotal
return ap_op_leave(aTHX_ markix, 9 7 16
846 19 apophis_do_exists(aTHX_ who, mark[1], mark[2], NULL, 2) ? &PL_sv_yes : &PL_sv_no);
847 }
848  
849 static OP *
850 17 pp_apophis_fetch(pTHX)
851 {
852 17 ▶ AP_OP_PROLOGUE(AP_FETCH);
Branch: 1 branch
BranchTrueFalseTotal
AP_OP_PROLOGUE(AP_FETCH); 0 17 17
853 15 return ap_op_leave(aTHX_ markix,
854 17 sv_2mortal(apophis_do_fetch(aTHX_ who, mark[1], mark[2], NULL, 2)));
855 }
856  
857 static OP *
858 10 pp_apophis_verify(pTHX)
859 {
860 10 ▶ AP_OP_PROLOGUE(AP_VERIFY);
Branch: 1 branch
BranchTrueFalseTotal
AP_OP_PROLOGUE(AP_VERIFY); 0 10 10
861 10 ▶ return ap_op_leave(aTHX_ markix,
Branch: 1 branch
BranchTrueFalseTotal
return ap_op_leave(aTHX_ markix, 4 6 10
862 10 apophis_do_verify(aTHX_ who, mark[1], mark[2], NULL, 2) ? &PL_sv_yes : &PL_sv_no);
863 }
864  
865 static OP *
866 10 pp_apophis_remove(pTHX)
867 {
868 10 ▶ AP_OP_PROLOGUE(AP_REMOVE);
Branch: 1 branch
BranchTrueFalseTotal
AP_OP_PROLOGUE(AP_REMOVE); 0 10 10
869 10 ▶ return ap_op_leave(aTHX_ markix,
Branch: 1 branch
BranchTrueFalseTotal
return ap_op_leave(aTHX_ markix, 7 3 10
870 10 apophis_do_remove(aTHX_ who, mark[1], mark[2], NULL, 2) ? &PL_sv_yes : &PL_sv_no);
871 }
872  
873 /* Once for the process: the XSUBs behind the names, the ops' names for
874 * B and the debugger, and the hook on entersub's check. */
875 static void
876 15 ap_boot_ops(pTHX)
877 {
878 int i;
879  
880 105 ▶ for (i = 0; i < AP_NOPS; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < AP_NOPS; i++) { 90 15 105
881 90 CV *cv = get_cv(form("Apophis::%s", ap_method[i]), 0);
882 90 ap_xsub[i] = CvXSUB(cv);
883 90 XopENTRY_set(&ap_xop[i], xop_name, ap_xop_name[i]);
884 90 XopENTRY_set(&ap_xop[i], xop_desc, ap_xop_desc[i]);
885 90 XopENTRY_set(&ap_xop[i], xop_class, OA_UNOP);
886 90 Perl_custom_op_register(aTHX_ ap_pp[i], &ap_xop[i]);
887 }
888 #if PERL_VERSION_GE(5,16,0)
889 15 wrap_op_checker(OP_ENTERSUB, ap_ck_entersub, &ap_next_ck_entersub);
890 #else
891 if (!ap_next_ck_entersub) {
892 ap_next_ck_entersub = PL_check[OP_ENTERSUB];
893 PL_check[OP_ENTERSUB] = ap_ck_entersub;
894 }
895 #endif
896 15 }
897  
898  
899 /* ================================================================== */
900 /* The public C ABI */
901 /* ================================================================== */
902  
903 /* Wraps the static core above into the table consumers reach through
904 * Apophis::_abi_ptr. Included here, after everything it wraps. */
905 #include "ap_abi_impl.h"
906  
907  
908 /* ================================================================== */
909 /* XSUBs */
910 /* ================================================================== */
911  
912 MODULE = Apophis PACKAGE = Apophis
913  
914 BOOT:
915 15 ap_boot_ops(aTHX);
916  
917 # ------------------------------------------------------------------ #
918 # new(class, %args) -> blessed object #
919 # ------------------------------------------------------------------ #
920  
921 SV *
922 new(class, ...)
923 const char *class
924 PREINIT:
925 HV *self;
926 SV *self_ref;
927 int i;
928 35 const char *namespace_str = NULL;
929 35 STRLEN namespace_len = 0;
930 35 const char *store_dir = NULL;
931 35 STRLEN store_dir_len = 0;
932 unsigned char ns_bytes[16];
933 CODE:
934 35 ▶ if ((items - 1) % 2 != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2 != 0) 1 34 35
935 1 croak("Apophis->new: odd number of arguments");
936  
937 /* Parse args */
938 87 ▶ for (i = 1; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) { 53 34 87
939 53 const char *key = SvPV_nolen(ST(i));
940 53 ▶ if (strEQ(key, "namespace")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "namespace")) { 32 21 53
941 64 namespace_str = SvPV(ST(i+1), namespace_len);
942 21 ▶ } else if (strEQ(key, "store_dir")) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strEQ(key, "store_dir")) { 20 1 21
943 40 store_dir = SvPV(ST(i+1), store_dir_len);
944 }
945 }
946  
947 34 ▶ if (!namespace_str)
Branch: 1 branch
BranchTrueFalseTotal
if (!namespace_str) 2 32 34
948 2 croak("Apophis->new: 'namespace' is required");
949  
950 /* Derive namespace UUID */
951 32 apophis_derive_namespace(ns_bytes, namespace_str, namespace_len);
952  
953 /* Build object */
954 32 self = newHV();
955 32 hv_stores(self, "_ns_bytes", newSVpvn((const char *)ns_bytes, 16));
956 32 hv_stores(self, "_ns_str", apophis_uuid_to_sv(aTHX_ ns_bytes));
957  
958 32 ▶ if (store_dir)
Branch: 1 branch
BranchTrueFalseTotal
if (store_dir) 19 13 32
959 19 hv_stores(self, "store_dir", newSVpvn(store_dir, store_dir_len));
960  
961 32 self_ref = newRV_noinc((SV *)self);
962 32 sv_bless(self_ref, gv_stashpv(class, GV_ADD));
963 32 RETVAL = self_ref;
964 OUTPUT:
965 RETVAL
966  
967 # ------------------------------------------------------------------ #
968 # namespace() -> UUID string #
969 # ------------------------------------------------------------------ #
970  
971 SV *
972 namespace(self)
973 SV *self
974 PREINIT:
975 HV *hv;
976 SV **svp;
977 CODE:
978 9 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 1 8 9
979 1 croak("Apophis::namespace: not an object");
980 8 hv = (HV *)SvRV(self);
981 8 svp = hv_fetchs(hv, "_ns_str", 0);
982 8 ▶ if (!svp || !SvOK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) 7 1 8
if (!svp || !SvOK(*svp)) 1 6 7
983 2 croak("Apophis: object has no namespace");
984 6 RETVAL = newSVsv(*svp);
985 OUTPUT:
986 RETVAL
987  
988 # ------------------------------------------------------------------ #
989 # identify(\$content) -> UUID string #
990 # ------------------------------------------------------------------ #
991  
992 SV *
993 identify(self, content_ref)
994 SV *self
995 SV *content_ref
996 ALIAS:
997 op_identify = 1
998 PREINIT:
999 unsigned char uuid[16];
1000 CODE:
1001 6 apophis_do_identify(aTHX_ ap_who[AP_IDENTIFY][ix], self, content_ref, uuid);
1002 2 RETVAL = apophis_uuid_to_sv(aTHX_ uuid);
1003 OUTPUT:
1004 RETVAL
1005  
1006 # ------------------------------------------------------------------ #
1007 # identify_file($path) -> UUID string #
1008 # ------------------------------------------------------------------ #
1009  
1010 SV *
1011 identify_file(self, path)
1012 SV *self
1013 const char *path
1014 PREINIT:
1015 HV *hv;
1016 const unsigned char *ns;
1017 unsigned char uuid[16];
1018 PerlIO *fh;
1019 CODE:
1020 6 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 1 5 6
1021 1 croak("Apophis::identify_file: not an object");
1022 5 hv = (HV *)SvRV(self);
1023 5 ns = apophis_get_ns(aTHX_ hv);
1024  
1025 5 fh = PerlIO_open(path, "rb");
1026 5 ▶ if (!fh)
Branch: 1 branch
BranchTrueFalseTotal
if (!fh) 1 4 5
1027 1 croak("Apophis::identify_file: cannot open '%s': %s",
1028 path, strerror(errno));
1029  
1030 4 apophis_identify_stream(aTHX_ uuid, ns, fh);
1031 4 PerlIO_close(fh);
1032  
1033 4 RETVAL = apophis_uuid_to_sv(aTHX_ uuid);
1034 OUTPUT:
1035 RETVAL
1036  
1037 # ------------------------------------------------------------------ #
1038 # path_for($id, %opts) -> path string #
1039 # ------------------------------------------------------------------ #
1040  
1041 SV *
1042 path_for(self, id, ...)
1043 SV *self
1044 SV *id
1045 PREINIT:
1046 HV *hv;
1047 12 HV *opts = NULL;
1048 const char *store_dir;
1049 STRLEN store_dir_len;
1050 const char *id_str;
1051 STRLEN id_len;
1052 char path[APOPHIS_PATH_MAX];
1053 int path_len;
1054 CODE:
1055 12 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 1 11 12
1056 1 croak("Apophis::path_for: not an object");
1057 11 hv = (HV *)SvRV(self);
1058  
1059 /* Parse optional key-value pairs into opts HV */
1060 11 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 2 9 11
1061 int i;
1062 2 ▶ if ((items - 2) % 2 != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 2) % 2 != 0) 1 1 2
1063 1 croak("Apophis::path_for: odd number of optional arguments");
1064 1 opts = newHV();
1065 1 sv_2mortal((SV *)opts);
1066 2 ▶ for (i = 2; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i += 2) { 1 1 2
1067 STRLEN klen;
1068 1 const char *k = SvPV(ST(i), klen);
1069 1 hv_store(opts, k, klen, SvREFCNT_inc(ST(i+1)), 0);
1070 }
1071 }
1072  
1073 10 store_dir = apophis_get_store_dir(aTHX_ hv, opts, &store_dir_len);
1074 10 id_str = SvPV(id, id_len);
1075  
1076 10 path_len = apophis_path(path, sizeof(path),
1077 store_dir, store_dir_len,
1078 id_str, id_len);
1079 9 RETVAL = newSVpvn(path, path_len);
1080 OUTPUT:
1081 RETVAL
1082  
1083 # ------------------------------------------------------------------ #
1084 # store(\$content, %opts) -> UUID string #
1085 # ------------------------------------------------------------------ #
1086  
1087 SV *
1088 store(self, content_ref, ...)
1089 SV *self
1090 SV *content_ref
1091 ALIAS:
1092 op_store = 1
1093 PREINIT:
1094 char id_str[HORUS_FMT_STR_LEN + 1];
1095 CODE:
1096 15 apophis_do_store(aTHX_ ap_who[AP_STORE][ix], self, content_ref, &ST(0), items, id_str);
1097 7 RETVAL = newSVpvn(id_str, HORUS_FMT_STR_LEN);
1098 OUTPUT:
1099 RETVAL
1100  
1101 # ------------------------------------------------------------------ #
1102 # fetch($id, %opts) -> \$content or undef #
1103 # ------------------------------------------------------------------ #
1104  
1105 SV *
1106 fetch(self, id, ...)
1107 SV *self
1108 SV *id
1109 ALIAS:
1110 op_fetch = 1
1111 CODE:
1112 6 RETVAL = apophis_do_fetch(aTHX_ ap_who[AP_FETCH][ix], self, id, &ST(0), items);
1113 OUTPUT:
1114 RETVAL
1115  
1116 # ------------------------------------------------------------------ #
1117 # exists($id, %opts) -> bool #
1118 # ------------------------------------------------------------------ #
1119  
1120 bool
1121 exists(self, id, ...)
1122 SV *self
1123 SV *id
1124 ALIAS:
1125 op_exists = 1
1126 CODE:
1127 9 RETVAL = apophis_do_exists(aTHX_ ap_who[AP_EXISTS][ix], self, id, &ST(0), items);
1128 OUTPUT:
1129 RETVAL
1130  
1131 # ------------------------------------------------------------------ #
1132 # remove($id, %opts) -> bool #
1133 # ------------------------------------------------------------------ #
1134  
1135 bool
1136 remove(self, id, ...)
1137 SV *self
1138 SV *id
1139 ALIAS:
1140 op_remove = 1
1141 CODE:
1142 4 RETVAL = apophis_do_remove(aTHX_ ap_who[AP_REMOVE][ix], self, id, &ST(0), items);
1143 OUTPUT:
1144 RETVAL
1145  
1146 # ------------------------------------------------------------------ #
1147 # verify($id, %opts) -> bool #
1148 # ------------------------------------------------------------------ #
1149  
1150 bool
1151 verify(self, id, ...)
1152 SV *self
1153 SV *id
1154 ALIAS:
1155 op_verify = 1
1156 CODE:
1157 5 RETVAL = apophis_do_verify(aTHX_ ap_who[AP_VERIFY][ix], self, id, &ST(0), items);
1158 OUTPUT:
1159 RETVAL
1160  
1161 # ------------------------------------------------------------------ #
1162 # store_many(\@refs, %opts) -> @ids #
1163 # ------------------------------------------------------------------ #
1164  
1165 void
1166 store_many(self, refs, ...)
1167 SV *self
1168 SV *refs
1169 PREINIT:
1170 HV *hv;
1171 10 HV *opts = NULL;
1172 const unsigned char *ns;
1173 const char *store_dir;
1174 STRLEN store_dir_len;
1175 AV *av;
1176 I32 len, i;
1177 PPCODE:
1178 10 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 1 9 10
1179 1 croak("Apophis::store_many: not an object");
1180 9 hv = (HV *)SvRV(self);
1181 9 ns = apophis_get_ns(aTHX_ hv);
1182  
1183 9 ▶ if (!SvROK(refs) || SvTYPE(SvRV(refs)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(refs) || SvTYPE(SvRV(refs)) != SVt_PVAV) 8 1 9
if (!SvROK(refs) || SvTYPE(SvRV(refs)) != SVt_PVAV) 2 6 8
1184 3 croak("Apophis::store_many: first argument must be an array ref");
1185 6 av = (AV *)SvRV(refs);
1186 6 len = av_len(av) + 1;
1187  
1188 6 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 2 4 6
1189 int j;
1190 2 ▶ if ((items - 2) % 2 != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 2) % 2 != 0) 1 1 2
1191 1 croak("Apophis::store_many: odd number of optional arguments");
1192 1 opts = newHV();
1193 1 sv_2mortal((SV *)opts);
1194 2 ▶ for (j = 2; j < items; j += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 2; j < items; j += 2) { 1 1 2
1195 STRLEN klen;
1196 1 const char *k = SvPV(ST(j), klen);
1197 1 hv_store(opts, k, klen, SvREFCNT_inc(ST(j+1)), 0);
1198 }
1199 }
1200  
1201 5 store_dir = apophis_get_store_dir(aTHX_ hv, opts, &store_dir_len);
1202  
1203 5 ▶ EXTEND(SP, len);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, len); 5 0 5
EXTEND(SP, len); 0 5 5
1204 12 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 9 3 12
1205 9 SV **svp = av_fetch(av, i, 0);
1206 SV *content_sv;
1207 const char *content;
1208 STRLEN content_len;
1209 unsigned char uuid[16];
1210 char id_str[HORUS_FMT_STR_LEN + 1];
1211 char path[APOPHIS_PATH_MAX];
1212 apophis_stat_t st;
1213  
1214 9 ▶ if (!svp || !SvROK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvROK(*svp)) 8 1 9
if (!svp || !SvROK(*svp)) 1 7 8
1215 2 croak("Apophis::store_many: element %d must be a scalar ref",
1216 (int)i);
1217  
1218 7 content_sv = SvRV(*svp);
1219 7 content = SvPV(content_sv, content_len);
1220  
1221 7 apophis_identify_content(uuid, ns, content, content_len);
1222 7 horus_format_uuid(id_str, uuid, HORUS_FMT_STR);
1223  
1224 7 apophis_path(path, sizeof(path),
1225 store_dir, store_dir_len,
1226 id_str, HORUS_FMT_STR_LEN);
1227  
1228 7 ▶ if (apophis_stat(path, &st) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_stat(path, &st) != 0) { 3 4 7
1229 3 apophis_ensure_parent_dir(path);
1230 3 apophis_atomic_write(aTHX_ path, content, content_len);
1231 }
1232  
1233 7 PUSHs(sv_2mortal(newSVpvn(id_str, HORUS_FMT_STR_LEN)));
1234 }
1235  
1236 # ------------------------------------------------------------------ #
1237 # find_missing(\@ids, %opts) -> @missing_ids #
1238 # ------------------------------------------------------------------ #
1239  
1240 void
1241 find_missing(self, ids, ...)
1242 SV *self
1243 SV *ids
1244 PREINIT:
1245 HV *hv;
1246 9 HV *opts = NULL;
1247 const char *store_dir;
1248 STRLEN store_dir_len;
1249 AV *av;
1250 I32 len, i;
1251 PPCODE:
1252 9 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 1 8 9
1253 1 croak("Apophis::find_missing: not an object");
1254 8 hv = (HV *)SvRV(self);
1255  
1256 8 ▶ if (!SvROK(ids) || SvTYPE(SvRV(ids)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ids) || SvTYPE(SvRV(ids)) != SVt_PVAV) 7 1 8
if (!SvROK(ids) || SvTYPE(SvRV(ids)) != SVt_PVAV) 2 5 7
1257 3 croak("Apophis::find_missing: first argument must be an array ref");
1258 5 av = (AV *)SvRV(ids);
1259 5 len = av_len(av) + 1;
1260  
1261 5 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 2 3 5
1262 int j;
1263 2 ▶ if ((items - 2) % 2 != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 2) % 2 != 0) 1 1 2
1264 1 croak("Apophis::find_missing: odd number of optional arguments");
1265 1 opts = newHV();
1266 1 sv_2mortal((SV *)opts);
1267 2 ▶ for (j = 2; j < items; j += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 2; j < items; j += 2) { 1 1 2
1268 STRLEN klen;
1269 1 const char *k = SvPV(ST(j), klen);
1270 1 hv_store(opts, k, klen, SvREFCNT_inc(ST(j+1)), 0);
1271 }
1272 }
1273  
1274 4 store_dir = apophis_get_store_dir(aTHX_ hv, opts, &store_dir_len);
1275  
1276 13 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 9 4 13
1277 9 SV **svp = av_fetch(av, i, 0);
1278 const char *id_str;
1279 STRLEN id_len;
1280 char path[APOPHIS_PATH_MAX];
1281 apophis_stat_t st;
1282  
1283 9 ▶ if (!svp || !SvOK(*svp)) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) continue; 8 1 9
if (!svp || !SvOK(*svp)) continue; 1 7 8
1284  
1285 7 id_str = SvPV(*svp, id_len);
1286 7 apophis_path(path, sizeof(path),
1287 store_dir, store_dir_len, id_str, id_len);
1288  
1289 7 ▶ if (apophis_stat(path, &st) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (apophis_stat(path, &st) != 0) { 4 3 7
1290 4 ▶ XPUSHs(sv_2mortal(newSVpvn(id_str, id_len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(id_str, id_len))); 0 4 4
1291 }
1292 }
1293  
1294 # ------------------------------------------------------------------ #
1295 # meta($id, %opts) -> \%meta or undef #
1296 # ------------------------------------------------------------------ #
1297  
1298 SV *
1299 meta(self, id, ...)
1300 SV *self
1301 SV *id
1302 PREINIT:
1303 HV *hv;
1304 11 HV *opts = NULL;
1305 const char *store_dir;
1306 STRLEN store_dir_len;
1307 const char *id_str;
1308 STRLEN id_len;
1309 char path[APOPHIS_PATH_MAX];
1310 int path_len;
1311 char meta_path[APOPHIS_PATH_MAX];
1312 HV *meta;
1313 CODE:
1314 11 ▶ if (!sv_isobject(self))
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(self)) 1 10 11
1315 1 croak("Apophis::meta: not an object");
1316 10 hv = (HV *)SvRV(self);
1317  
1318 10 ▶ if (items > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) { 2 8 10
1319 int i;
1320 2 ▶ if ((items - 2) % 2 != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 2) % 2 != 0) 1 1 2
1321 1 croak("Apophis::meta: odd number of optional arguments");
1322 1 opts = newHV();
1323 1 sv_2mortal((SV *)opts);
1324 2 ▶ for (i = 2; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i += 2) { 1 1 2
1325 STRLEN klen;
1326 1 const char *k = SvPV(ST(i), klen);
1327 1 hv_store(opts, k, klen, SvREFCNT_inc(ST(i+1)), 0);
1328 }
1329 }
1330  
1331 9 store_dir = apophis_get_store_dir(aTHX_ hv, opts, &store_dir_len);
1332 9 id_str = SvPV(id, id_len);
1333 9 path_len = apophis_path(path, sizeof(path),
1334 store_dir, store_dir_len,
1335 id_str, id_len);
1336 9 apophis_build_meta_path(meta_path, sizeof(meta_path),
1337 path, path_len);
1338  
1339 9 meta = apophis_meta_read(aTHX_ meta_path);
1340 9 ▶ if (meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (meta) { 3 6 9
1341 3 RETVAL = newRV_noinc((SV *)meta);
1342 } else {
1343 6 RETVAL = &PL_sv_undef;
1344 }
1345 OUTPUT:
1346 RETVAL
1347  
1348 # ------------------------------------------------------------------ #
1349 # The public C ABI (ap_abi.h) #
1350 # ------------------------------------------------------------------ #
1351  
1352 # _abi_ptr() -> the address of the process-wide table, as a UV.
1353 #
1354 # Private. UV and PTR2UV rather than IV and PTR2IV because an address is
1355 # unsigned: PTR2IV hands back a NEGATIVE integer wherever the .so maps with
1356 # the top bit set - Solaris/illumos amd64 loads libraries high, and so does
1357 # any 32-bit build in the upper 2GB - which makes a consumer's `$ptr > 0`
1358 # sanity check fail on a perfectly usable pointer.
1359  
1360 UV
1361 _abi_ptr()
1362 CODE:
1363 2 ▶ RETVAL = PTR2UV(&AP_ABI);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PTR2UV(&AP_ABI); 0 2 2
1364 OUTPUT:
1365 RETVAL
1366  
1367 # _abi_selftest($store, \$content, $name, $fh)
1368 # -> ($id, $path, $ns_of_name, $id_of_fh, $short_id_rc, $probe_rc, $probe_dirlen)
1369 #
1370 # Drives the table through its own function pointers, so the suite exercises
1371 # the ABI the way a consumer does rather than the way the XSUBs do. Writes the
1372 # blob, exactly as store() would. The test compares both answers against the
1373 # Perl API - two implementations of one algorithm agreeing is the assertion,
1374 # not an assumption. The rest of the table rides along: the namespace derived
1375 # from $name, the id of what $fh reads, build_path's refusal of a short id, and
1376 # store_of asked for part of the store, as a consumer probing with NULLs does.
1377  
1378 void
1379 _abi_selftest(self, content_ref, name, fh_sv)
1380 SV *self
1381 SV *content_ref
1382 SV *name
1383 SV *fh_sv
1384 PREINIT:
1385 18 const ap_abi *A = &AP_ABI;
1386 18 const unsigned char *ns = NULL;
1387 18 const unsigned char *ns_only = NULL;
1388 18 const char *dir = NULL;
1389 18 const char *dir_only = NULL;
1390 18 STRLEN dirlen = 0;
1391 18 STRLEN only_len = 0;
1392 const char *content;
1393 STRLEN content_len;
1394 const char *name_str;
1395 STRLEN name_len;
1396 unsigned char id[16];
1397 unsigned char ns_bytes[16];
1398 unsigned char fh_id[16];
1399 char id_str[HORUS_FMT_STR_LEN + 1];
1400 char ns_str[HORUS_FMT_STR_LEN + 1];
1401 char fh_str[HORUS_FMT_STR_LEN + 1];
1402 char path[APOPHIS_PATH_MAX];
1403 int path_len;
1404 int short_rc;
1405 int probe_rc;
1406 int null_rc;
1407 PPCODE:
1408 18 ▶ if (!A->store_of(aTHX_ self, &ns, &dir, &dirlen))
Branch: 1 branch
BranchTrueFalseTotal
if (!A->store_of(aTHX_ self, &ns, &dir, &dirlen)) 12 6 18
1409 12 croak("Apophis::_abi_selftest: not a store");
1410 6 ▶ if (!SvROK(content_ref))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(content_ref)) 1 5 6
1411 1 croak("Apophis::_abi_selftest: content must be a scalar reference");
1412 10 ▶ content = SvPV(SvRV(content_ref), content_len);
Branch: 1 branch
BranchTrueFalseTotal
content = SvPV(SvRV(content_ref), content_len); 5 0 5
1413 5 name_str = SvPV(name, name_len);
1414  
1415 5 probe_rc = A->store_of(aTHX_ self, &ns_only, NULL, NULL)
1416 5 + A->store_of(aTHX_ self, NULL, &dir_only, NULL)
1417 5 + A->store_of(aTHX_ self, NULL, NULL, &only_len);
1418 5 null_rc = A->store_of(aTHX_ NULL, &ns_only, &dir_only, &only_len);
1419  
1420 5 A->derive_ns(ns_bytes, name_str, name_len);
1421 5 A->format_id(ns_str, ns_bytes);
1422  
1423 5 A->identify(id, ns, content, content_len);
1424 5 A->format_id(id_str, id);
1425  
1426 5 short_rc = A->build_path(path, sizeof(path), dir, dirlen, id_str, 3);
1427 5 path_len = A->build_path(path, sizeof(path), dir, dirlen,
1428 id_str, HORUS_FMT_STR_LEN);
1429 5 ▶ if (path_len < 0 || (size_t)path_len >= sizeof(path)) /* # uncoverable condition left count:1 */
Branch: 2 branches
BranchTrueFalseTotal
if (path_len < 0 || (size_t)path_len >= sizeof(path)) /* # uncoverable condition left count:1 */ 5 0 5
if (path_len < 0 || (size_t)path_len >= sizeof(path)) /* # uncoverable condition left count:1 */ 1 4 5
1430 1 croak("Apophis::_abi_selftest: path too long");
1431  
1432 4 A->write_atomic(aTHX_ path, content, content_len);
1433  
1434 4 A->identify_fh(aTHX_ fh_id, ns, IoIFP(sv_2io(fh_sv)));
1435 4 A->format_id(fh_str, fh_id);
1436  
1437 4 ▶ EXTEND(SP, 8);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 8); 0 4 4
1438 4 PUSHs(sv_2mortal(newSVpvn(id_str, HORUS_FMT_STR_LEN)));
1439 4 PUSHs(sv_2mortal(newSVpvn(path, path_len)));
1440 4 PUSHs(sv_2mortal(newSVpvn(ns_str, HORUS_FMT_STR_LEN)));
1441 4 PUSHs(sv_2mortal(newSVpvn(fh_str, HORUS_FMT_STR_LEN)));
1442 4 PUSHs(sv_2mortal(newSViv(short_rc)));
1443 4 PUSHs(sv_2mortal(newSViv(probe_rc)));
1444 4 PUSHs(sv_2mortal(newSVuv(only_len)));
1445 4 PUSHs(sv_2mortal(newSViv(null_rc)));
1446  
1447 # _abi_write($path, \$content)
1448 #
1449 # The table's write_atomic on a path of the caller's choosing, as a consumer
1450 # that built its own path would call it.
1451  
1452 void
1453 _abi_write(path, content_ref)
1454 const char *path
1455 SV *content_ref
1456 PREINIT:
1457 const char *content;
1458 STRLEN content_len;
1459 PPCODE:
1460 6 ▶ if (!SvROK(content_ref))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(content_ref)) 1 5 6
1461 1 croak("Apophis::_abi_write: content must be a scalar reference");
1462 5 content = SvPV(SvRV(content_ref), content_len);
1463 5 AP_ABI.write_atomic(aTHX_ path, content, content_len);
1464 3 XSRETURN_EMPTY;
« blib/arch/Apophis/Install/Files.pm ↑ Summary blib/lib/Apophis.pm »