From unknown Sat Jun 21 12:18:49 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#49547 <49547@debbugs.gnu.org> To: bug#49547 <49547@debbugs.gnu.org> Subject: Status: [PATCH v2 2/4] home-services: Add home-run-on-change-service-type Reply-To: bug#49547 <49547@debbugs.gnu.org> Date: Sat, 21 Jun 2025 19:18:49 +0000 retitle 49547 [PATCH v2 2/4] home-services: Add home-run-on-change-service-= type reassign 49547 guix-patches submitter 49547 Andrew Tropin severity 49547 normal tag 49547 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 13 14:18:20 2021 Received: (at submit) by debbugs.gnu.org; 13 Jul 2021 18:18:20 +0000 Received: from localhost ([127.0.0.1]:41958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Mz6-0000Tk-By for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:20 -0400 Received: from lists.gnu.org ([209.51.188.17]:40882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Mz4-0000Tc-CU for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mz4-0004Nx-6f for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:18 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]:35509) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mz2-0007Cn-NW for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:17 -0400 Received: by mail-lf1-x12d.google.com with SMTP id i5so22114249lfe.2 for ; Tue, 13 Jul 2021 11:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:date:message-id:mime-version; bh=CM4tFsqYNLOPPbf/KJDGWYjTRZjO1d6HTCQncmSQDsA=; b=ynszYC6lcSGABGuK08P/983Xf4xZxlQrEddaSc5FVJZvq9eEQSJN86mAdINxnAvae4 GHlxGkt4CKCpszFYeXhF8Kntq7POpD25eSz8lOvOGGSMIjnHWC+6iq9FZ3nmX6MJ2IhH 4lL5JAI/IieXztl/BlUTejwDbUk2ogH99I0a8PRzSaZZWkSEy+hkHj8LI23JQ0w08jrR anBNqaZqn9KwqNFy3Wr6Cz97vJ8yh7RPJJJmG1+S3HMUq1DurlVLJOFESK+YUB3rSVOZ PbqbmnBK8xF1ZwKoII49Qj/rsldGZEAlA4PYCk6pCOSr6cqoTrTZ0cJreNPKwBNby78n XSJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:date:message-id :mime-version; bh=CM4tFsqYNLOPPbf/KJDGWYjTRZjO1d6HTCQncmSQDsA=; b=XIzqeJ336MF/FsE0MBlqIFzIcA0Owie94afF/TAnHOt2Tt/hhIAUR1j4UGJIeu1HPL FDyaHL0+NSIxofHdqKrWD7DxG61+P0ykNVtAOo37oVsT38cPc/catJeD5W4vKLAPWoPS X+665hoSYV0h+eQ+dZw1SUQ2mW/95CEyCiolgmKx7PskG9H4IP09/sKCems6aSFHo3/l EUOM13WWsDH25AL3ISnFXZ7LP8s3jyQ6zoMXpr8QjK4uHlgO5f3yMnSarySgert36w5y pQuifArtg60tECLVYDrC3ag1ED4qF/q3HOik0fjPDMPjLybRi1R4ChUgj8A0sas7nleJ O2uQ== X-Gm-Message-State: AOAM532OhhKopGclw01bnbUNvREerFiSyqWOEb4u4TVDBjAu38xQ5zL1 M2IObAdk2VJUXu1THI19VviwWwmE+YBPoQ== X-Google-Smtp-Source: ABdhPJy2z8lEXcDnqlvVmFFromu5iZkHVrImwfZln8nTgx8umvF5TyIMG2SpvgM1JjFDae+ZPULhyA== X-Received: by 2002:a05:6512:1594:: with SMTP id bp20mr4458549lfb.178.1626200293999; Tue, 13 Jul 2021 11:18:13 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id w7sm1514611lfu.52.2021.07.13.11.18.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 11:18:13 -0700 (PDT) From: Andrew Tropin To: guix-patches@gnu.org Subject: [PATCH v2 2/4] home-services: Add home-run-on-change-service-type In-Reply-To: <87bl76m6b7.fsf@trop.in> Date: Mon, 5 Jul 2021 18:39:44 +0300 Message-ID: <875yxem679.fsf@trop.in> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: none client-ip=2a00:1450:4864:20::12d; envelope-from=andrew@trop.in; helo=mail-lf1-x12d.google.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -0.2 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.2 (-) Service allows to trigger actions during activation if file or directory specified by pattern is changed. --- gnu/home-services.scm | 95 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index a89a061a81..fadad3133e 100644 --- a/gnu/home-services.scm +++ b/gnu/home-services.scm @@ -37,7 +37,8 @@ home-environment-variables-service-type home-files-service-type home-run-on-first-login-service-type - home-activation-service-type) + home-activation-service-type + home-run-on-change-service-type) #:re-export (service service-type @@ -326,3 +327,95 @@ directory. @command{activate} script automatically called during reconfiguration or generation switching. This service can be extended with one gexp, but many times, and all gexps must be idempotent."))) + +;;; +;;; On-change. +;;; + +(define (compute-on-change-gexp eval-gexps? pattern-gexp-tuples) + #~(begin + (define (equal-regulars? file1 file2) + "Check if FILE1 and FILE2 are bit for bit identical." + (let* ((cmp-binary #$(file-append + (@ (gnu packages base) diffutils) "/bin/cmp")) + (status (system* cmp-binary file1 file2))) + (= status 0))) + + (define (equal-symlinks? symlink1 symlink2) + "Check if SYMLINK1 and SYMLINK2 are pointing to the same target." + (string=? (readlink symlink1) (readlink symlink2))) + + (define (equal-directories? dir1 dir2) + "Check if DIR1 and DIR2 have the same content." + (define (ordinary-file file) + (not (or (string=? file ".") + (string=? file "..")))) + (let* ((files1 (scandir dir1 ordinary-file)) + (files2 (scandir dir2 ordinary-file))) + (if (equal? files1 files2) + (map (lambda (file) + (equal-files? + (string-append dir1 "/" file) + (string-append dir2 "/" file))) + files1) + #f))) + + (define (equal-files? file1 file2) + "Compares files, symlinks or directories of the same type." + (case (file-type file1) + ((directory) (equal-directories? file1 file2)) + ((symlink) (equal-symlinks? file1 file2)) + ((regular) (equal-regulars? file1 file2)) + (else + (display "The file type is unsupported by on-change service.\n") + #f))) + + (define (file-type file) + (stat:type (lstat file))) + + (define (something-changed? file1 file2) + (cond + ((and (not (file-exists? file1)) + (not (file-exists? file2))) #f) + ((or (not (file-exists? file1)) + (not (file-exists? file2))) #t) + + ((not (eq? (file-type file1) (file-type file2))) #t) + + (else + (not (equal-files? file1 file2))))) + + (define expressions-to-eval + (map + (lambda (x) + (let* ((file1 (string-append (getenv "GUIX_OLD_HOME") "/" (car x))) + (file2 (string-append (getenv "GUIX_NEW_HOME") "/" (car x))) + (_ (format #t "Comparing ~a and\n~10t~a..." file1 file2)) + (any-changes? (something-changed? file1 file2)) + (_ (format #t " done (~a)\n" + (if any-changes? "changed" "same")))) + (if any-changes? (cadr x) ""))) + '#$pattern-gexp-tuples)) + + (if #$eval-gexps? + (begin + (display "Evaling on-change gexps.\n\n") + (for-each primitive-eval expressions-to-eval) + (display "On-change gexps evaluation finished.\n\n")) + (display "\ +On-change gexps won't evaluated, disabled by service configuration.\n")))) + +(define home-run-on-change-service-type + (service-type (name 'home-run-on-change) + (extensions + (list (service-extension + home-activation-service-type + identity))) + (compose concatenate) + (extend compute-on-change-gexp) + (default-value #t) + (description "\ +G-expressions to run if the specified files have changed since the +last generation. The extension should be a list of lists where the +first element is the pattern for file or directory that expected to be +changed, and the second element is the G-expression to be evaluated."))) -- 2.32.0 From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 13 14:27:17 2021 Received: (at control) by debbugs.gnu.org; 13 Jul 2021 18:27:18 +0000 Received: from localhost ([127.0.0.1]:42000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3N7l-0000n2-N1 for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:27:17 -0400 Received: from mail-lf1-f44.google.com ([209.85.167.44]:45779) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3N7i-0000mj-N0 for control@debbugs.gnu.org; Tue, 13 Jul 2021 14:27:16 -0400 Received: by mail-lf1-f44.google.com with SMTP id 22so21736987lfy.12 for ; Tue, 13 Jul 2021 11:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version; bh=xDsO7Vl9Dc1E46OwFe2aFH2eTkSzfGkavHD55mENqS4=; b=fjgcbpNmtNvwlYBFZ2/TV0aP+4tSoM5Yz1Ya6HSDqRKko9ME+KLNSvPjTwI8h6Gz2C w1903gicAP4BX32IZzttZt3ZIUlW+hD1cSmrOepid0E+TBaWZTxCDiL4D8qkqYrONHtY cBCq+3A6vJWcOkHC4a0LeEqtZkjo0gBCPpfMdcK+nJfD9yaJ+ftTs7bhCvUuDr58dwci BCxU6YqYVvR8a5sos8gNll1syKeX9PwXgAHnkDPY5c7C5V4bS1ez7FYuvlBxKfZtv63U 28IH1iPyMCtxz62+fswOd3YChsfv6U4RuUGO21jXLf9a5+qZc4sbVntwomP8ao+9YnqP hBvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=xDsO7Vl9Dc1E46OwFe2aFH2eTkSzfGkavHD55mENqS4=; b=JKo3SbW5txl5ghuL0lG8MaHaXlAUFNYmoJwaMlEJpqinYhMMhWrCxmq7+A0vEDH4Zs ALEZTxO9diRYLxCQ+9hdrC874yZJ346OGI7I6wgs1Ey1gCItp4d2xHiwVo3NvEGpB6wm 8Hvuu1BLqUGMnRl/apNM84V/NKkpLWZRPHhMFGTEjmyP5CeH9iesEyZo53HYy4NIUMU5 4aVZZVvEi+x+Gv/AhGQsmK71UZpmKKb736W5LoL4ImARzWCWWkcnYv9fHBVPY7PZtBcS RcT/qEoe4wgzwAtCvh/TUMROlcaPyBvc1aENVdm91eYWKKWRBidOa6QxTR9PpwTRxIj6 CMrg== X-Gm-Message-State: AOAM5337bSQjeq9vaM/Y5olzw5eDJvSFnDw/OEKwn1P+eCwmgLRkMeUX YtuwwecyJu8zmvI0pJKeoDJPrRA/G0NH5A== X-Google-Smtp-Source: ABdhPJxQ64WNB+b4tsK2QJcgOPe9g9pc4PScR7J+nLkbSperNAWn01HDfJ54GpZx+emSaMsPiNhHQg== X-Received: by 2002:a05:6512:604:: with SMTP id b4mr4596735lfe.184.1626200828432; Tue, 13 Jul 2021 11:27:08 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id h19sm1598146ljj.23.2021.07.13.11.27.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 11:27:08 -0700 (PDT) From: Andrew Tropin To: control@debbugs.gnu.org Subject: Merging accidentially created tickets Date: Tue, 13 Jul 2021 21:26:59 +0300 Message-ID: <87pmvmkr2k.fsf@trop.in> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) merge 49419 49546 49547 49548 49549 From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 14 06:41:53 2021 Received: (at 49547) by debbugs.gnu.org; 14 Jul 2021 10:41:53 +0000 Received: from localhost ([127.0.0.1]:43056 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3cKu-0006np-Rv for submit@debbugs.gnu.org; Wed, 14 Jul 2021 06:41:53 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:49804) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3cKs-0006nf-N2 for 49547@debbugs.gnu.org; Wed, 14 Jul 2021 06:41:51 -0400 Received: from butterfly.local ([188.188.219.228]) by baptiste.telenet-ops.be with bizsmtp id Uyho250024wFxCU01yho4V; Wed, 14 Jul 2021 12:41:49 +0200 Message-ID: Subject: Re: [bug#49547] [PATCH v2 2/4] home-services: Add home-run-on-change-service-type From: Maxime Devos To: Andrew Tropin , 49547@debbugs.gnu.org Date: Wed, 14 Jul 2021 12:41:35 +0200 In-Reply-To: <875yxem679.fsf@trop.in> References: <875yxem679.fsf@trop.in> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-mkytba5u9lUi6lMxzjLA" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1626259309; bh=ygaCzqA4H65mnD9pVF+X4Gd9vA7VzjqB5RVp/uRUPqE=; h=Subject:From:To:Date:In-Reply-To:References; b=SAVPas7ZA78StCVUSDCRw0hCj9xAKydB+EZ9RUDfW/sGdaeOAUab4v0wsBUs9lUe0 af0O7bmOOHb+XizLoPGq1VJQ7/x3ab3k036fPjBza+fEENgqNv+7hipLLgyK3clEDW Tw4Y1CyWGuGW/nJxA8BxAgUjfpR/hC6EEy2sjb/RNx2chcIS1XbvlR8v+dmHWLb7co RDB5btVdygly0qAK/+0QsBEEfzs3VafCpD0B11NE8q5kmhgo0NZkJ4iASQvkpQoEp5 N0kTdFOpNvZXJnpf/5kbS7Niua1sYz+5dRY3G4c/GjfaPQBbL3q9rLU/Sb+KqX8IHN jVjFP/0K5Nk+A== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 49547 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-mkytba5u9lUi6lMxzjLA Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Andrew Tropin schreef op ma 05-07-2021 om 18:39 [+0300]: > + (define (equal-regulars? file1 file2) > + "Check if FILE1 and FILE2 are bit for bit identical." > + (let* ((cmp-binary #$(file-append > + (@ (gnu packages base) diffutils) "/bin/cm= p")) > + (status (system* cmp-binary file1 file2))) > + (=3D status 0))) Is there any particular reason to shell out to "cmp" instead of doing the comparison in Guile? Starting a process isn't the most efficient thing. Try "time /run/current-system/profile/bin echo", on my system, it takes about 2--3 milliseconds for "echo" to finish even though it only had to print a newline character. Compare with "time echo" (to use the shell built-in "echo"), it takes 0.000s seconds on my system. 3 milliseconds isn't much by itself, but this can accumulate, so I would implement the comparison in Guile. As an optimisation, you could look at the value returned by "lstat". If the 'size' is different, then 'equal-regulars?' can return #f without reading the file. If the 'inode' and 'device' are equal, then 'equal-regulars?' can return #t I think (at least on conventional file systems like btrfs and ext4). Greetings, Maxime. --=-mkytba5u9lUi6lMxzjLA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYO6/XxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7n/oAP466Q+yNDWKN85lWBzh23gFcgJl jrkXgXv4gkpEv3VRIgD/QDFM7IlVUX9HSbQLJfKHjSZ7HfYDCsi7PabVpzizfwI= =I3D3 -----END PGP SIGNATURE----- --=-mkytba5u9lUi6lMxzjLA-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 15 04:48:21 2021 Received: (at 49547) by debbugs.gnu.org; 15 Jul 2021 08:48:21 +0000 Received: from localhost ([127.0.0.1]:46776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3x2b-0002Zr-Ed for submit@debbugs.gnu.org; Thu, 15 Jul 2021 04:48:21 -0400 Received: from mail-lf1-f43.google.com ([209.85.167.43]:41897) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3x2Z-0002Zf-Ra for 49547@debbugs.gnu.org; Thu, 15 Jul 2021 04:48:20 -0400 Received: by mail-lf1-f43.google.com with SMTP id g8so2715584lfh.8 for <49547@debbugs.gnu.org>; Thu, 15 Jul 2021 01:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=VKp0vfPepaR2VcR93+sa8fAlOCx3b4/7bvXW8fkH+6E=; b=b4U60HzB0vOQXaHXzLIz8CchjPE/RrrU2m5PbxuB3zZ6cDHNlTzWs5Fid5LYwjq+E3 G87bbKd4JFdQAQeDGiBMsfPfCl6iUNcqEg8wANeFM43L8a7uYIyoTIuy64RlXO4ykYYz yrYuCbja3HwKOQKmFNFv9pw+asqBZw+EUVa+VErHhkTcj2LcjQeRUcxI+NtdZFuCUdkm G7VqQyGuEOqeWF2nYe9lTvNBe3PXyJM1tg4zEJ/4QVjk7NfCqQq6Wyk02AyIgSdWuY0q rT+30H0sr7pWawexabEDGFV0BFT6TawyE3VJgo3oC2iSCS+ECw6EWyqmBeVwCehJFBkw 7Ncg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=VKp0vfPepaR2VcR93+sa8fAlOCx3b4/7bvXW8fkH+6E=; b=VSbvRE7bfgy9uyxLqN26MYJeseZXHOok6kpZ2bmunkhj3vqGDYODcHWeN4wy0nD9YE jyaef/WsFJfSOkCDknB4IIC1sXYU56yjM5m6lJQHN5WZYfXAjuwnjQBdMQmwxyP6ZKoQ 1nMgf8F0DRiOrFPxIdNTX/sS5Zv/qnNMmlOK/xs78lSQw8E6vgjb18H2dMrQO9QYsb52 GuJuj222izyDamdYwjPhBu7fG+lg9KW9Evwq1y6K5LKhFKkZanmfnhMvH7pQCTtcn85b Z6ekb/ux4XCWhXmAqzVgt1nT+y1DPAkvZ7gKt51JnU8bfY6SYUUIZHBl4/3OkPjihgR1 Zb9g== X-Gm-Message-State: AOAM530xYdK4Qayr0tLNiJyE7oivB5pE0A3utk7cnZBEpM9DDpCtzgwA 0EUCfQScSQ0QrxgYSn/qL42xuQ== X-Google-Smtp-Source: ABdhPJxYcApFtmFfX/MYTYUSZb8GUVecn3p3IxVPR36+hXJkr7tA0d4KLI90+DeMEbaUlkaeduY/RA== X-Received: by 2002:a05:6512:3447:: with SMTP id j7mr2447814lfr.558.1626338893674; Thu, 15 Jul 2021 01:48:13 -0700 (PDT) Received: from localhost ([176.52.100.214]) by smtp.gmail.com with ESMTPSA id x10sm356657lfu.263.2021.07.15.01.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 01:48:12 -0700 (PDT) From: Andrew Tropin To: Maxime Devos , 49547@debbugs.gnu.org Subject: Re: [bug#49547] [PATCH v2 2/4] home-services: Add home-run-on-change-service-type In-Reply-To: References: <875yxem679.fsf@trop.in> Date: Thu, 15 Jul 2021 11:46:35 +0300 Message-ID: <87fswg2cd0.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 49547 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Maxime Devos writes: > Andrew Tropin schreef op ma 05-07-2021 om 18:39 [+0300]: >> + (define (equal-regulars? file1 file2) >> + "Check if FILE1 and FILE2 are bit for bit identical." >> + (let* ((cmp-binary #$(file-append >> + (@ (gnu packages base) diffutils) "/bin/cmp")) >> + (status (system* cmp-binary file1 file2))) >> + (= status 0))) > > Is there any particular reason to shell out to "cmp" instead > of doing the comparison in Guile? Starting a process isn't > the most efficient thing. > > Try "time /run/current-system/profile/bin echo", on my system, > it takes about 2--3 milliseconds for "echo" to finish > even though it only had to print a newline character. > Compare with "time echo" (to use the shell built-in "echo"), > it takes 0.000s seconds on my system. > > 3 milliseconds isn't much by itself, but this can accumulate, > so I would implement the comparison in Guile. > > As an optimisation, you could look at the value returned by "lstat". > If the 'size' is different, then 'equal-regulars?' can return #f > without reading the file. If the 'inode' and 'device' are equal, > then 'equal-regulars?' can return #t I think (at least on conventional > file systems like btrfs and ext4). No specific reason. Yep, spawning a new process can be expensive, but it's not clear how much time will take the comparison itself and if it worth it to optimize "startup time". I'm not very fluent with guile internals and not sure if reimplementation of cmp in guile would improve or worsen the performance, but it obviously could intoduce some bugs. I found Xinglu's idea of the usage of well-tested cmp to be a reasonable solution here. Also, this service is expected to be used with small amount of files and because many of them are symlinks to the store even smaller number of them will trigger the execution of cmp, so I find the performance optimization to be preliminary here and propose to address the issue when and if it appear someday. However, the ideas about size and inodes are good, easy to implement and I find them potentially useful to prevent unecessary external process spawning. The patch with those improvements are below: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-toberebased-home-services-Prevent-unecessary-system-.patch Content-Transfer-Encoding: quoted-printable From=208dd0c06fb64c8b516418cbdf8c385a6c817e7f26 Mon Sep 17 00:00:00 2001 From: Andrew Tropin Date: Thu, 15 Jul 2021 09:44:30 +0300 Subject: [PATCH] (toberebased) home-services: Prevent unecessary system* ca= ll =2D-- gnu/home-services.scm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index 78e5603edf..9afb70f0a7 100644 =2D-- a/gnu/home-services.scm +++ b/gnu/home-services.scm @@ -341,8 +341,13 @@ with one gexp, but many times, and all gexps must be i= dempotent."))) "Check if FILE1 and FILE2 are bit for bit identical." (let* ((cmp-binary #$(file-append (@ (gnu packages base) diffutils) "/bin/cmp"= )) =2D (status (system* cmp-binary file1 file2))) =2D (=3D status 0))) + (stats1 (lstat file1)) + (stats2 (lstat file2))) + (cond + ((=3D (stat:ino stats1) (stat:ino stats2)) #t) + ((not (=3D (stat:size stats1) (stat:size stats2))) #f) + + (else (=3D (system* cmp-binary file1 file2) 0))))) =20 (define (equal-symlinks? symlink1 symlink2) "Check if SYMLINK1 and SYMLINK2 are pointing to the same target." =2D-=20 2.32.0 --=-=-= Content-Type: text/plain Thank you for suggestions!) --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmDv9esPHGFuZHJld0B0 cm9wLmluAAoJECII0glYwd6wHH4P/RRohchbd9qOOFASUcDQS5tq0RKJ3N7hfO5X aGRfyARItrj5oA8SYKw9OHrd1b4fIeDO0DVWScEJJ33rv8Exg+dgOkHJ0b5AN1wY zdOKRIRRqOuCy8u5oAZwkK4jBy1Ewz6UV+5MGWO0Y5GpgHMlHiRU0A2XtEkU7Ubh 2MdP/BDTqNY4mj6sAxneA0V8PRgUIQiau3QwDEPX6f2JAJduPC/niVHUTi4nYFkS BfCt32T6x6Z5mOO4isRMzTstwnNAtSreTapIHIxr3mLi+QAimv/1txGqxQY6dRQK qQHwAc2P/PQ/UWgreRSzxAE4kKvFk6vl9dIAXVwdZheErflNCSzJO25ArfQz+913 hfOPv/KoILyXHL9PfzOwoEjZ2NEOs5YWd60SATYkT0VGZe0lNEhkE/uIPbo0gDTw JrYhVBV0sYxk85LKlQIPvJ6yjipXkMHRz130vAnJuWKNgXOKL+0Gf+NtDPBnzMl/ dKI7epQ3LOebdEcGbx3sdfre47WYdEmi1NTxBS2nEb5Tzt9+KQ+Cq3AQvg/vylfG A4+nAkTgETzSXGad6eBcvjOkQxkseverAm1zFx+kh3tjng7pSNB2AE2+kzf/W1JW YcYwAGNJWFLCQCkZm1YuWgIzcXqjXElLRvzgK+ZWbQZv11pH3Ik8cFSBcIXRqVQa 6YPfKK9e =d8Sg -----END PGP SIGNATURE----- --==-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 18 14:44:08 2021 Received: (at 49547) by debbugs.gnu.org; 18 Jul 2021 18:44:08 +0000 Received: from localhost ([127.0.0.1]:57255 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5Blo-000357-5x for submit@debbugs.gnu.org; Sun, 18 Jul 2021 14:44:08 -0400 Received: from newton.telenet-ops.be ([195.130.132.45]:32858) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5Blm-00034z-Mv for 49547@debbugs.gnu.org; Sun, 18 Jul 2021 14:44:07 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by newton.telenet-ops.be (Postfix) with ESMTPS id 4GSVW14LwSzMqqJm for <49547@debbugs.gnu.org>; Sun, 18 Jul 2021 18:17:33 +0200 (CEST) Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by michel.telenet-ops.be with bizsmtp id WgHX250070mfAB406gHXYc; Sun, 18 Jul 2021 18:17:32 +0200 Message-ID: <3e972a6c839a48edf7fecb88a3ad4fd9bc0dfcee.camel@telenet.be> Subject: Re: [bug#49547] [PATCH v2 2/4] home-services: Add home-run-on-change-service-type From: Maxime Devos To: Andrew Tropin , 49547@debbugs.gnu.org Date: Sun, 18 Jul 2021 18:17:31 +0200 In-Reply-To: <87fswg2cd0.fsf@trop.in> References: <875yxem679.fsf@trop.in> <87fswg2cd0.fsf@trop.in> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-viPv9Fv7hxpLtIqaG2vR" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1626625052; bh=DQmmJqOz0YcQP9cllhbOxyZ1EeB0KEc9y3nkK5SjUaQ=; h=Subject:From:To:Date:In-Reply-To:References; b=BEVb5M7KOysfWtV45sBa839SFT173zr0QSXVyImEf88m9BuFTFS5qq9Hc5Z5UlrR4 Z8eDWwtPw30kH5E/cXsfV9r9RU3Hd9MV4w7IyQodRpUAMNwWddGTd0vmbPnfFkBZh5 LhnUORk8daOGav/wV3GB7zeUQAJFF5O9rvxNPY+nb/xZoq6IOS43GbUN1FANlmAPxs 3WtPcw1ToGHKsJK98MQWMfBxZKajLh37uPhrVZMU8jQW1qQdkMblhzJHUciG5Kzfci MT5elbLh/GIDdLJbqIWmogs3ud3Tea5Rdf3n0eXMQX1FFPNWsab5Bpo/0yQrPyTFLw N3VtL5qB9Bcaw== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 49547 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-viPv9Fv7hxpLtIqaG2vR Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Andrew Tropin schreef op do 15-07-2021 om 11:46 [+0300]: > No specific reason. Yep, spawning a new process can be expensive, but > it's not clear how much time will take the comparison itself and if it > worth it to optimize "startup time". I'm not very fluent with guile > internals and not sure if reimplementation of cmp in guile would improve > or worsen the performance, but it obviously could intoduce some bugs. I > found Xinglu's idea of the usage of well-tested cmp to be a reasonable > solution here. Sounds reasonable to me. > Also, this service is expected to be used with small amount of files and > because many of them are symlinks to the store even smaller number of > them will trigger the execution of cmp, so I find the performance > optimization to be preliminary here and propose to address the issue > when and if it appear someday. >=20 > However, the ideas about size and inodes are good, easy to implement and > I find them potentially useful to prevent unecessary external process > spawning. The patch with those improvements are below: [...] Greetings, Maxime. --=-viPv9Fv7hxpLtIqaG2vR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYPRUGxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7hIgAPsExp+jqfgfoKVMHgODzJREQOdI yT8ZpvE3XC/p2J51bwEA0Hj3KBHI2TnyUq0uZUkpRrsGFKF9tB/9gdb4IjCF5gA= =sLoh -----END PGP SIGNATURE----- --=-viPv9Fv7hxpLtIqaG2vR-- From unknown Sat Jun 21 12:18:49 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 23 Sep 2021 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator