;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018, 2019 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (test-status) #:use-module (guix status) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-64) #:use-module (rnrs bytevectors) #:use-module (rnrs io ports) #:use-module (ice-9 match)) (test-begin "status") (test-equal "compute-status, no-op" (build-status) (let-values (((port get-status) (build-event-output-port compute-status))) (display "foo\nbar\n\baz\n" port) (get-status))) (test-equal "compute-status, builds + substitutes" (list (build-status (building (list (build "foo.drv" "x86_64-linux"))) (downloading (list (download "bar" "http://example.org/bar" #:size 500 #:start 'now)))) (build-status (building (list (build "foo.drv" "x86_64-linux"))) (downloading (list (download "bar" "http://example.org/bar" #:size 500 #:transferred 42 #:start 'now)))) (build-status (builds-completed (list (build "foo.drv" "x86_64-linux"))) (download
This patch makes the "/ID" field optional.

If the environment variable GS_GENERATE_UUIDS is set to "0" or "no", it will
not write out the "/ID" field (if that's permissible).

Upstream does not want to do this.

See: https://bugs.ghostscript.com/show_bug.cgi?id=698208
diff --git a/devices/vector/gdevpdf.c b/devices/vector/gdevpdf.c
index c5abefde2..3859fc088 100644
--- a/devices/vector/gdevpdf.c
+++ b/devices/vector/gdevpdf.c
@@ -1909,8 +1909,11 @@ static int pdf_linearise(gx_device_pdf *pdev, pdf_linearisation_t *linear_params
      * +1 for the linearisation dict and +1 for the primary hint stream.
      */
     linear_params->FirsttrailerOffset = gp_ftell(linear_params->Lin_File.file);
-    gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R/ID[%s%s]/Prev %d>>\nstartxref\r\n0\n%%%%EOF\n        \n",
-        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber, fileID, fileID, 0);
+    gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R",
+        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber);
+    if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 && strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) /* ID is mandatory when encrypting */
+        gs_snprintf(LDict, sizeof(LDict), "/ID[%s%s]", fileID, fileID);
+    gs_snprintf(LDict, sizeof(LDict), "/Prev %d>>\nstartxref\r\n0\n%%%%EOF\n        \n", 0);
     gp_fwrite(LDict, strlen(LDict), 1, linear_params->Lin_File.file);
 
     /* Write document catalog (Part 4) */
@@ -2445,8 +2448,11 @@ static int pdf_linearise(gx_device_pdf *pdev, pdf_linearisation_t *linear_params
     if (code != 0)
         return_error(gs_error_ioerror);
 
-    gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R/ID[%s%s]/Prev %"PRId64">>\nstartxref\r\n0\n%%%%EOF\n",
-        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber, fileID, fileID, mainxref);
+    gs_snprintf(LDict, sizeof(LDict), "\ntrailer\n<</Size %ld/Info %d 0 R/Root %d 0 R",
+        linear_params->LastResource + 3, pdev->ResourceUsage[linear_params->Info_id].NewObjectNumber, pdev->ResourceUsage[linear_params->Catalog_id].NewObjectNumber);
+    if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) /* ID is mandatory when encrypting */
+        gs_snprintf(LDict, sizeof(LDict), "/ID[%s%s]", fileID, fileID);
+    gs_snprintf(LDict, sizeof(LDict), "/Prev %"PRId64">>\nstartxref\r\n0\n%%%%EOF\n", mainxref);
     gp_fwrite(LDict, strlen(LDict), 1, linear_params->sfile);
 
     code = gp_fseek(linear_params->sfile, pdev->ResourceUsage[HintStreamObj].LinearisedOffset, SEEK_SET);
@@ -3139,10 +3145,12 @@ pdf_close(gx_device * dev)
             stream_puts(s, "trailer\n");
             pprintld3(s, "<< /Size %ld /Root %ld 0 R /Info %ld 0 R\n",
                   pdev->next_id, Catalog_id, Info_id);
-            stream_puts(s, "/ID [");
-            psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
-            psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
-            stream_puts(s, "]\n");
+            if (pdev->OwnerPassword.size > 0 || !(!getenv("GS_GENERATE_UUIDS") || (strcasecmp(getenv("GS_GENERATE_UUIDS"), "0") != 0 || strcasecmp(getenv("GS_GENERATE_UUIDS"), "no") != 0))) { /* ID is mandatory when encrypting */
+                stream_puts(s, "/ID [");
+                psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
+                psdf_write_string(pdev->strm, pdev->fileID, sizeof(pdev->fileID), 0);
+                stream_puts(s, "]\n");
+            }
             if (pdev->OwnerPassword.size > 0) {
                 pprintld1(s, "/Encrypt %ld 0 R ", Encrypt_id);
             }
#:start 'now)))) (build-status ;; "bar" is now only listed as a download. (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121))) (downloads-completed (list (download "bar" "http://example.org/bar" #:size 999 #:transferred 999 #:start 'now #:end 'now))))) (let-values (((port get-status) (build-event-output-port (lambda (event status) (compute-status event status #:current-time (const 'now) #:derivation-path->output-path (match-lambda ("bar.drv" "bar"))))))) (display "@ build-started foo.drv - x86_64-linux 121\n" port) (display "@ build-started bar.drv - armhf-linux bar.log 144\n" port) (display "@ build-log 121 6\nHello!" port) (display "@ build-log 144 50 @ download-started bar http://example.org/bar 999\n" port) (let ((first (get-status))) (display "@ build-log 121 30\n@ build-started FAKE!.drv 555\n") (display "@ build-log 144 54 @ download-progress bar http://example.org/bar 999 42\n" port) (let ((second (get-status))) (display "@ download-succeeded bar http://example.org/bar 999\n" port) (display "@ build-succeeded foo.drv\n" port) (display "@ build-succeeded bar.drv\n" port) (list first second (get-status)))))) (test-equal "compute-status, build completion" (list (build-status (building (list (build "foo.drv" "x86_64-linux" #:id 121)))) (build-status (building (list (build "foo.drv" "x86_64-linux" #:id 121 #:completion 0.)))) (build-status (building (list (build "foo.drv" "x86_64-linux" #:id 121 #:completion 50.)))) (build-status (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121 #:completion 100.))))) (let-values (((port get-status) (build-event-output-port (lambda (event status) (compute-status event status #:current-time (const 'now)))))) (display "@ build-started foo.drv - x86_64-linux 121\n" port) (display "@ build-log 121 6\nHello!" port) (let ((first (get-status))) (display "@ build-log 121 20\n[ 0/100] building X\n" port) (display "@ build-log 121 6\nHello!" port) (let ((second (get-status))) (display "@ build-log 121 20\n[50/100] building Y\n" port) (display "@ build-log 121 6\nHello!" port) (let ((third (get-status))) (display "@ build-log 121 21\n[100/100] building Z\n" port) (display "@ build-log 121 6\nHello!" port) (display "@ build-succeeded foo.drv\n" port) (list first second third (get-status))))))) (test-equal "compute-status, build phase" (list (build-status (building (list (build "foo.drv" "x86_64-linux" #:id 121 #:phase 'configure)))) (build-status (building (list (build "foo.drv" "x86_64-linux" #:id 121 #:phase 'configure #:completion 50.)))) (build-status (building (list (build "foo.drv" "x86_64-linux" #:id 121 #:phase 'install)))) (build-status (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121 #:phase 'install))))) (let-values (((port get-status) (build-event-output-port (lambda (event status) (compute-status event status #:current-time (const 'now)))))) (display "@ build-started foo.drv - x86_64-linux 121\n" port) (display "@ build-log 121 27\nstarting phase `configure'\n" port) (display "@ build-log 121 6\nabcde!" port) (let ((first (get-status))) (display "@ build-log 121 20\n[50/100] building Y\n" port) (display "@ build-log 121 6\nfghik!" port) (let ((second (get-status))) (display "@ build-log 121 21\n[100/100] building Z\n" port) (display "@ build-log 121 25\nstarting phase `install'\n" port) (display "@ build-log 121 6\nlmnop!" port) (let ((third (get-status))) (display "@ build-succeeded foo.drv\n" port) (list first second third (get-status))))))) (test-end "status")