From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Famulari Subject: bug#32126: call-with-temporary-directory rarely cleans up after itself Date: Thu, 12 Jul 2018 20:51:36 -0400 Message-ID: <20180713005136.GA22011@jasmine.lan> References: <20180711185937.GA16510@jasmine.lan> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Bn2rw/3z4jIqBvZU" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdmJZ-0004YA-KV for bug-guix@gnu.org; Thu, 12 Jul 2018 20:52:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdmJW-00084U-HI for bug-guix@gnu.org; Thu, 12 Jul 2018 20:52:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:49654) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fdmJW-00084H-Cd for bug-guix@gnu.org; Thu, 12 Jul 2018 20:52:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fdmJW-00057z-4v for bug-guix@gnu.org; Thu, 12 Jul 2018 20:52:02 -0400 In-Reply-To: <20180711185937.GA16510@jasmine.lan> Sender: "Debbugs-submit" Resent-Message-ID: Content-Disposition: inline List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: 32126@debbugs.gnu.org --Bn2rw/3z4jIqBvZU Content-Type: multipart/mixed; boundary="sm4nu43k4a2Rpi4c" Content-Disposition: inline --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here's a patch that copies the ((guix build utils) delete-file-recursively) procedure and uses it in ((guix utils) call-with-temporary-directory). However, with the patch there is an error in the test 'gexp->script #:module-path': ------ actual-value: #f actual-error: + (system-error + "lstat" + "~A: ~S" + ("No such file or directory" + "/tmp/guix-directory.6CrC8B/guix/base32.scm") + (2)) result: FAIL ------ Continuing to investigate... --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-utils-Really-clean-up-temporary-directories.patch" Content-Transfer-Encoding: quoted-printable =46rom e3181f30ca0711e79aab9d71d798344dfb4636b5 Mon Sep 17 00:00:00 2001 =46rom: Leo Famulari Date: Wed, 11 Jul 2018 20:24:29 -0400 Subject: [PATCH] utils: Really clean up temporary directories. * guix/utils.scm (delete-file-recursively): New variable. (call-with-temporary-directory): Use DELETE-FILE-RECURSIVELY instead of RMDIR. --- guix/utils.scm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/guix/utils.scm b/guix/utils.scm index f934b6ed1..9e260c90c 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -33,6 +33,7 @@ #:use-module (srfi srfi-35) #:use-module (srfi srfi-39) #:use-module (ice-9 binary-ports) + #:use-module (ice-9 ftw) #:autoload (rnrs io ports) (make-custom-binary-input-port) #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!)) #:use-module (guix memoization) @@ -620,6 +621,32 @@ call." (false-if-exception (close out)) (false-if-exception (delete-file template)))))) =20 +;; Copied from (guix build utils) +(define* (delete-file-recursively dir + #:key follow-mounts?) + "Delete DIR recursively, like `rm -rf', without following symlinks. Don= 't +follow mount points either, unless FOLLOW-MOUNTS? is true. Report but ign= ore +errors." + (let ((dev (stat:dev (lstat dir)))) + (file-system-fold (lambda (dir stat result) ; enter? + (or follow-mounts? + (=3D dev (stat:dev stat)))) + (lambda (file stat result) ; leaf + (delete-file file)) + (const #t) ; down + (lambda (dir stat result) ; up + (rmdir dir)) + (const #t) ; skip + (lambda (file stat errno result) + (format (current-error-port) + "warning: failed to delete ~a: ~a~%" + file (strerror errno))) + #t + dir + + ;; Don't follow symlinks. + lstat))) + (define (call-with-temporary-directory proc) "Call PROC with a name of a temporary directory; close the directory and delete it when leaving the dynamic extent of this call." @@ -631,7 +658,7 @@ delete it when leaving the dynamic extent of this call." (lambda () (proc tmp-dir)) (lambda () - (false-if-exception (rmdir tmp-dir)))))) + (false-if-exception (delete-file-recursively tmp-dir)))))) =20 (define (with-atomic-file-output file proc) "Call PROC with an output port for the file that is going to replace FIL= E. --=20 2.18.0 --sm4nu43k4a2Rpi4c-- --Bn2rw/3z4jIqBvZU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEsFFZSPHn08G5gDigJkb6MLrKfwgFAltH95UACgkQJkb6MLrK fwg3Ag/8CVwxPcVkiW2UfgcBZRs4seRyb+7UIkjj2tPAAeMnl18oJsj4mqt9WEOh HPtknFRoww2MJG9Xt/j8T1kY4B2jI3zLrivX0p3VfuYGEQNxEGg4iwEsvA4jGxPm bZeVkPYpXeQ4l9hjepGcL3G6U3OK9my9abxCkdoBHP9g04tybutrCFjjwsf4yOLa JPhuHQ7uzse3UCVTAEE3K6HzhLkRdzQQOHrh5OtYJ2eK4lixBW5euCKMX1LADUpu /9CxXGUPi8Ky2CggQny8JUH+zoFWqUdl3mKRQzE7fAYuNNkv357+U91ifbSMKwsJ JHJWIH1dStIPpuYgcAsIBXf+V2k3Crj0E9PJ76Lf3SDjz6nRmcgClRAchhoQTSt1 sqbwUjxFOoA0aqCNoWBG5OJ3ks5XhuR/rQj0g7rNzPVkPrY3xzjXyN273jX3b0mJ Q72eVq7I8nUfNVqUmeiD1CEexxuCuaXMamzoXPfNi7U9DpM5XIXd0WMrkTU9Vo1o 0Kt7oZ7O9IBqAjC3gcZQ79fHD0eDHcCiUoyJ4UkThAudQpXgZ+HyDmKELe9heevm JhGEcLZhp5lm0D1xS/qltcyVyA56oGEiDbtL7Q35WMB40ME6hTbM6JOomkVWa00b rztg4ZACny3gSr4HCkLm/My8oO1W78c/5msFwZWHSTgIvFO/UPg= =M22g -----END PGP SIGNATURE----- --Bn2rw/3z4jIqBvZU--