]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4451 / 1: Use mkstemp for PNG scale down
authorMasamichi Hosoda <trueroad@trueroad.jp>
Sun, 14 Jun 2015 14:17:19 +0000 (23:17 +0900)
committerMasamichi Hosoda <trueroad@trueroad.jp>
Sat, 20 Jun 2015 13:10:06 +0000 (22:10 +0900)
In procedure ``scale-down-image'' (ps-to-png.scm),
temp files are created by mkstemp.

scm/ps-to-png.scm

index e890eaa746f52df2b5be0cd7a5d71f66e1e9be96..a8a170cc2fb31886c5074d904cafe1e9660f8bf7 100644 (file)
        '("pnmtopng"))))
 
 (define (scale-down-image factor file)
-  (let* ((old (string-append file ".old"))
+  (let* ((port-tmp1 (make-tmpfile))
+         (tmp1-name (port-filename port-tmp1))
+         (port-tmp2 (make-tmpfile))
+         (tmp2-name (port-filename port-tmp2))
          ;; Netpbm commands (pngtopnm, pnmscale, pnmtopng)
          ;; outputs only standard output instead of a file.
          ;; So we need pipe and redirection.
          (cmd
           (ly:format
            "~a \"~a\" | ~a -reduce ~a | ~a -compression 9 > \"~a\""
-           (search-pngtopam) old
+           (search-pngtopam) tmp1-name
            (search-pamscale) factor
            (search-pnmtopng)
-           file)))
+           tmp2-name)))
 
-    (rename-file file old)
+    (copy-binary-file file tmp1-name)
     (ly:system-with-shell cmd)
-    (delete-file old)))
+    (copy-binary-file tmp2-name file)
+    (delete-file tmp1-name)
+    (delete-file tmp2-name)))
 
 (define-public (ps-page-count ps-name)
   (let* ((byte-count 10240)