GNU bug report logs - #49547
[PATCH v2 2/4] home-services: Add home-run-on-change-service-type

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Andrew Tropin <andrew@HIDDEN>; Keywords: patch; merged with #49419, #49546, #49548, #49549; dated Tue, 13 Jul 2021 18:19:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at 49547 <at> debbugs.gnu.org:


Received: (at 49547) by debbugs.gnu.org; 18 Jul 2021 18:44:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jul 18 14:44:08 2021
Received: from localhost ([127.0.0.1]:57255 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m5Blo-000357-5x
	for submit <at> 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 <maximedevos@HIDDEN>) id 1m5Blm-00034z-Mv
 for 49547 <at> 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 <at> 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@HIDDEN>
Subject: Re: [bug#49547] [PATCH v2 2/4] home-services: Add
 home-run-on-change-service-type
From: Maxime Devos <maximedevos@HIDDEN>
To: Andrew Tropin <andrew@HIDDEN>, 49547 <at> debbugs.gnu.org
Date: Sun, 18 Jul 2021 18:17:31 +0200
In-Reply-To: <87fswg2cd0.fsf@HIDDEN>
References: <875yxem679.fsf@HIDDEN>
 <ec097a03e2df002ef04a9ad80610ed3309a8dfce.camel@HIDDEN>
 <87fswg2cd0.fsf@HIDDEN>
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 <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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--





Information forwarded to guix-patches@HIDDEN:
bug#49547; Package guix-patches. Full text available.

Message received at 49547 <at> debbugs.gnu.org:


Received: (at 49547) by debbugs.gnu.org; 15 Jul 2021 08:48:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jul 15 04:48:21 2021
Received: from localhost ([127.0.0.1]:46776 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m3x2b-0002Zr-Ed
	for submit <at> 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 <andrew@HIDDEN>) id 1m3x2Z-0002Zf-Ra
 for 49547 <at> 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 <at> 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 <andrew@HIDDEN>
To: Maxime Devos <maximedevos@HIDDEN>, 49547 <at> debbugs.gnu.org
Subject: Re: [bug#49547] [PATCH v2 2/4] home-services: Add
 home-run-on-change-service-type
In-Reply-To: <ec097a03e2df002ef04a9ad80610ed3309a8dfce.camel@HIDDEN>
References: <875yxem679.fsf@HIDDEN>
 <ec097a03e2df002ef04a9ad80610ed3309a8dfce.camel@HIDDEN>
Date: Thu, 15 Jul 2021 11:46:35 +0300
Message-ID: <87fswg2cd0.fsf@HIDDEN>
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 <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--==-=-=
Content-Type: multipart/mixed; boundary="=-=-="

--=-=-=
Content-Type: text/plain

Maxime Devos <maximedevos@HIDDEN> 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 <andrew@HIDDEN>
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-----
--==-=-=--




Information forwarded to guix-patches@HIDDEN:
bug#49547; Package guix-patches. Full text available.

Message received at 49547 <at> debbugs.gnu.org:


Received: (at 49547) by debbugs.gnu.org; 14 Jul 2021 10:41:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jul 14 06:41:53 2021
Received: from localhost ([127.0.0.1]:43056 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m3cKu-0006np-Rv
	for submit <at> 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 <maximedevos@HIDDEN>) id 1m3cKs-0006nf-N2
 for 49547 <at> 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: <ec097a03e2df002ef04a9ad80610ed3309a8dfce.camel@HIDDEN>
Subject: Re: [bug#49547] [PATCH v2 2/4] home-services: Add
 home-run-on-change-service-type
From: Maxime Devos <maximedevos@HIDDEN>
To: Andrew Tropin <andrew@HIDDEN>, 49547 <at> debbugs.gnu.org
Date: Wed, 14 Jul 2021 12:41:35 +0200
In-Reply-To: <875yxem679.fsf@HIDDEN>
References: <875yxem679.fsf@HIDDEN>
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 <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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--





Information forwarded to guix-patches@HIDDEN:
bug#49547; Package guix-patches. Full text available.
Merged 49419 49546 49547 49548 49549. Request was from Andrew Tropin <andrew@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 13 Jul 2021 18:18:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jul 13 14:18:20 2021
Received: from localhost ([127.0.0.1]:41958 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1m3Mz6-0000Tk-By
	for submit <at> 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 <andrew@HIDDEN>) id 1m3Mz4-0000Tc-CU
 for submit <at> 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 <andrew@HIDDEN>) id 1m3Mz4-0004Nx-6f
 for guix-patches@HIDDEN; 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 <andrew@HIDDEN>) id 1m3Mz2-0007Cn-NW
 for guix-patches@HIDDEN; Tue, 13 Jul 2021 14:18:17 -0400
Received: by mail-lf1-x12d.google.com with SMTP id i5so22114249lfe.2
 for <guix-patches@HIDDEN>; 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 <guix-patches@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 13 Jul 2021 11:18:13 -0700 (PDT)
From: Andrew Tropin <andrew@HIDDEN>
To: guix-patches@HIDDEN
Subject: [PATCH v2 2/4] home-services: Add home-run-on-change-service-type
In-Reply-To: <87bl76m6b7.fsf@HIDDEN>
Date: Mon, 5 Jul 2021 18:39:44 +0300
Message-ID: <875yxem679.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: none client-ip=2a00:1450:4864:20::12d;
 envelope-from=andrew@HIDDEN; 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 <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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





Acknowledgement sent to Andrew Tropin <andrew@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#49547; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 18 Jul 2021 19:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.