+ if (zpm_readonly(&zpm) && noteifwritable) {
+ notenever = 1;
+ }
+
+ if (output && !notenever) {
+ struct stat outstat;
+ stat(output, &outstat);
+ outsize = outstat.st_size;
+ if (notealways || (outsize && status && (outsize || allowempty))) {
+ makenote = 1;
+ }
+ }
+
+ if (makenote) {
+ char note[1024];
+
+ zpm_import(&zpm, output, 0, hash);
+
+ if (status) {
+ sprintf(note, "%.64s script failed with code %d",
+ phase, status);
+
+ fail = HARD;
+ } else {
+ sprintf(note, "%.64s script succeeded", phase);
+ }
+ zpm_note_add(&zpm, pkgid, NULL, hash, note);
+ }
+
+ if (output && showoutput) {
+ char buf[4096];
+ int out = open(output, O_RDONLY);
+ ssize_t bytes;
+ if (out == -1) {
+ perror("can't open output file");
+ } else {
+ while ((bytes = read(out, buf, sizeof buf)) > 0) {
+ write(1, buf, bytes);
+ }
+ if (bytes == -1) {
+ perror("output file read error");
+ }
+ }
+ if (out != -1) {
+ close(out);
+ }
+ }
+