unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* file-equal-p
       [not found] <87a61es8fh.fsf.ref@yahoo.com>
@ 2023-02-16  1:30 ` Po Lu
  2023-02-16  8:18   ` file-equal-p Eli Zaretskii
  2023-02-17  4:50   ` file-equal-p Richard Stallman
  0 siblings, 2 replies; 25+ messages in thread
From: Po Lu @ 2023-02-16  1:30 UTC (permalink / raw)
  To: emacs-devel

Someone says that Haiku changes the file access time every time `stat'
is called on a file, and as a result `file-equal-p' doesn't work, as it
compares the file attributes of both operands.

Ideas?  Thanks.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  1:30 ` file-equal-p Po Lu
@ 2023-02-16  8:18   ` Eli Zaretskii
  2023-02-16  8:43     ` file-equal-p Po Lu
  2023-02-17  4:50   ` file-equal-p Richard Stallman
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-16  8:18 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Date: Thu, 16 Feb 2023 09:30:58 +0800
> 
> Someone says that Haiku changes the file access time every time `stat'
> is called on a file, and as a result `file-equal-p' doesn't work, as it
> compares the file attributes of both operands.
> 
> Ideas?  Thanks.

Fix Haiku?  A 'stat' call accesses the directory and file's meta-data,
not the file itself, so what Haiku does makes no sense, IMO.

But if you cannot fix Haiku, a suitable haiku-only change in
file-equal-p, whereby the access times are exempt from comparison, is
a possibility.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  8:18   ` file-equal-p Eli Zaretskii
@ 2023-02-16  8:43     ` Po Lu
  2023-02-16  8:57       ` file-equal-p Eli Zaretskii
  2023-02-16  9:15       ` file-equal-p Andreas Schwab
  0 siblings, 2 replies; 25+ messages in thread
From: Po Lu @ 2023-02-16  8:43 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Fix Haiku?  A 'stat' call accesses the directory and file's meta-data,
> not the file itself, so what Haiku does makes no sense, IMO.
>
> But if you cannot fix Haiku, a suitable haiku-only change in
> file-equal-p, whereby the access times are exempt from comparison, is
> a possibility.

Something like this?

diff --git a/lisp/files.el b/lisp/files.el
index b0ec6bb09d0..dcd17df166a 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6360,7 +6360,17 @@ file-equal-p
       (let (f1-attr f2-attr)
         (and (setq f1-attr (file-attributes (file-truename file1)))
 	     (setq f2-attr (file-attributes (file-truename file2)))
-	     (equal f1-attr f2-attr))))))
+             (progn
+               ;; Haiku systems change the file's last access timestamp
+               ;; every time `stat' is called.  Make sure to not compare
+               ;; the timestamps in that case.
+               (when (and (eq system-type 'haiku)
+                          (consp (nthcdr 4 f1-attr))
+                          (consp (nthcdr 4 f2-attr)))
+                 (ignore-errors
+                   (setcar (nthcdr 4 f1-attr) nil)
+                   (setcar (nthcdr 4 f2-attr) nil)))
+	       (equal f1-attr f2-attr)))))))
 
 (defun file-in-directory-p (file dir)
   "Return non-nil if DIR is a parent directory of FILE.

BTW, what if a file changes in between the calls to `file-atttributes'
on any old GNU/Linux system?

Thanks.



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  8:43     ` file-equal-p Po Lu
@ 2023-02-16  8:57       ` Eli Zaretskii
  2023-02-16  9:59         ` file-equal-p Po Lu
  2023-02-16  9:15       ` file-equal-p Andreas Schwab
  1 sibling, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-16  8:57 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Thu, 16 Feb 2023 16:43:25 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Fix Haiku?  A 'stat' call accesses the directory and file's meta-data,
> > not the file itself, so what Haiku does makes no sense, IMO.
> >
> > But if you cannot fix Haiku, a suitable haiku-only change in
> > file-equal-p, whereby the access times are exempt from comparison, is
> > a possibility.
> 
> Something like this?

I'd prefer to have the original full comparison done first, and only
if it fails, do the tailored comparison only for Haiku.  That's
because most systems don't need this, and so testing the condition in
all cases will slow down those other systems.

> BTW, what if a file changes in between the calls to `file-atttributes'
> on any old GNU/Linux system?

Then we lose.  Any non-atomic file-related operation can be hit by
such race conditions.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  8:43     ` file-equal-p Po Lu
  2023-02-16  8:57       ` file-equal-p Eli Zaretskii
@ 2023-02-16  9:15       ` Andreas Schwab
  2023-02-16  9:58         ` file-equal-p Po Lu
  2023-02-16 10:35         ` file-equal-p Michael Albinus
  1 sibling, 2 replies; 25+ messages in thread
From: Andreas Schwab @ 2023-02-16  9:15 UTC (permalink / raw)
  To: Po Lu; +Cc: Eli Zaretskii, emacs-devel

On Feb 16 2023, Po Lu wrote:

> diff --git a/lisp/files.el b/lisp/files.el
> index b0ec6bb09d0..dcd17df166a 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -6360,7 +6360,17 @@ file-equal-p
>        (let (f1-attr f2-attr)
>          (and (setq f1-attr (file-attributes (file-truename file1)))
>  	     (setq f2-attr (file-attributes (file-truename file2)))
> -	     (equal f1-attr f2-attr))))))
> +             (progn
> +               ;; Haiku systems change the file's last access timestamp
> +               ;; every time `stat' is called.  Make sure to not compare
> +               ;; the timestamps in that case.
> +               (when (and (eq system-type 'haiku)
> +                          (consp (nthcdr 4 f1-attr))
> +                          (consp (nthcdr 4 f2-attr)))
> +                 (ignore-errors
> +                   (setcar (nthcdr 4 f1-attr) nil)
> +                   (setcar (nthcdr 4 f2-attr) nil)))
> +	       (equal f1-attr f2-attr)))))))

Why does that compare more than the inode and device number?  The other
attributes can change any time, if another process accesses the file or
modifies the inode between the two calls of file-attribute.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  9:15       ` file-equal-p Andreas Schwab
@ 2023-02-16  9:58         ` Po Lu
  2023-02-16 10:35         ` file-equal-p Michael Albinus
  1 sibling, 0 replies; 25+ messages in thread
From: Po Lu @ 2023-02-16  9:58 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Eli Zaretskii, emacs-devel

Andreas Schwab <schwab@suse.de> writes:

> On Feb 16 2023, Po Lu wrote:
>
>> diff --git a/lisp/files.el b/lisp/files.el
>> index b0ec6bb09d0..dcd17df166a 100644
>> --- a/lisp/files.el
>> +++ b/lisp/files.el
>> @@ -6360,7 +6360,17 @@ file-equal-p
>>        (let (f1-attr f2-attr)
>>          (and (setq f1-attr (file-attributes (file-truename file1)))
>>  	     (setq f2-attr (file-attributes (file-truename file2)))
>> -	     (equal f1-attr f2-attr))))))
>> +             (progn
>> +               ;; Haiku systems change the file's last access timestamp
>> +               ;; every time `stat' is called.  Make sure to not compare
>> +               ;; the timestamps in that case.
>> +               (when (and (eq system-type 'haiku)
>> +                          (consp (nthcdr 4 f1-attr))
>> +                          (consp (nthcdr 4 f2-attr)))
>> +                 (ignore-errors
>> +                   (setcar (nthcdr 4 f1-attr) nil)
>> +                   (setcar (nthcdr 4 f2-attr) nil)))
>> +	       (equal f1-attr f2-attr)))))))
>
> Why does that compare more than the inode and device number?  The other
> attributes can change any time, if another process accesses the file or
> modifies the inode between the two calls of file-attribute.

That's what I thought too, but it's not a good thing to doubt code that
has existed for a long time.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  8:57       ` file-equal-p Eli Zaretskii
@ 2023-02-16  9:59         ` Po Lu
  2023-02-16 11:52           ` file-equal-p Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Po Lu @ 2023-02-16  9:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Po Lu <luangruo@yahoo.com>
>> Cc: emacs-devel@gnu.org
>> Date: Thu, 16 Feb 2023 16:43:25 +0800
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > Fix Haiku?  A 'stat' call accesses the directory and file's meta-data,
>> > not the file itself, so what Haiku does makes no sense, IMO.
>> >
>> > But if you cannot fix Haiku, a suitable haiku-only change in
>> > file-equal-p, whereby the access times are exempt from comparison, is
>> > a possibility.
>> 
>> Something like this?
>
> I'd prefer to have the original full comparison done first, and only
> if it fails, do the tailored comparison only for Haiku.  That's
> because most systems don't need this, and so testing the condition in
> all cases will slow down those other systems.

But here, the test is only done at all when (eq system-type 'haiku).



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  9:15       ` file-equal-p Andreas Schwab
  2023-02-16  9:58         ` file-equal-p Po Lu
@ 2023-02-16 10:35         ` Michael Albinus
  2023-02-16 12:35           ` file-equal-p Po Lu
  1 sibling, 1 reply; 25+ messages in thread
From: Michael Albinus @ 2023-02-16 10:35 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Po Lu, Eli Zaretskii, emacs-devel

Andreas Schwab <schwab@suse.de> writes:

Hi,

> On Feb 16 2023, Po Lu wrote:
>
>> diff --git a/lisp/files.el b/lisp/files.el
>> index b0ec6bb09d0..dcd17df166a 100644
>> --- a/lisp/files.el
>> +++ b/lisp/files.el
>> @@ -6360,7 +6360,17 @@ file-equal-p
>>        (let (f1-attr f2-attr)
>>          (and (setq f1-attr (file-attributes (file-truename file1)))
>>  	     (setq f2-attr (file-attributes (file-truename file2)))
>> -	     (equal f1-attr f2-attr))))))
>> +             (progn
>> +               ;; Haiku systems change the file's last access timestamp
>> +               ;; every time `stat' is called.  Make sure to not compare
>> +               ;; the timestamps in that case.
>> +               (when (and (eq system-type 'haiku)
>> +                          (consp (nthcdr 4 f1-attr))
>> +                          (consp (nthcdr 4 f2-attr)))
>> +                 (ignore-errors
>> +                   (setcar (nthcdr 4 f1-attr) nil)
>> +                   (setcar (nthcdr 4 f2-attr) nil)))
>> +	       (equal f1-attr f2-attr)))))))
>
> Why does that compare more than the inode and device number?  The other
> attributes can change any time, if another process accesses the file or
> modifies the inode between the two calls of file-attribute.

For this we have file-attribute-file-identifier. So it might be
sufficient to call

--8<---------------cut here---------------start------------->8---
(equal (file-attribute-file-identifier f1-attr) (file-attribute-file-identifier f2-attr))
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  9:59         ` file-equal-p Po Lu
@ 2023-02-16 11:52           ` Eli Zaretskii
  2023-02-16 12:34             ` file-equal-p Po Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-16 11:52 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Thu, 16 Feb 2023 17:59:15 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Po Lu <luangruo@yahoo.com>
> >> Cc: emacs-devel@gnu.org
> >> Date: Thu, 16 Feb 2023 16:43:25 +0800
> >> 
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >> 
> >> > Fix Haiku?  A 'stat' call accesses the directory and file's meta-data,
> >> > not the file itself, so what Haiku does makes no sense, IMO.
> >> >
> >> > But if you cannot fix Haiku, a suitable haiku-only change in
> >> > file-equal-p, whereby the access times are exempt from comparison, is
> >> > a possibility.
> >> 
> >> Something like this?
> >
> > I'd prefer to have the original full comparison done first, and only
> > if it fails, do the tailored comparison only for Haiku.  That's
> > because most systems don't need this, and so testing the condition in
> > all cases will slow down those other systems.
> 
> But here, the test is only done at all when (eq system-type 'haiku).

It is still one more test, done for everyone.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16 11:52           ` file-equal-p Eli Zaretskii
@ 2023-02-16 12:34             ` Po Lu
  2023-02-16 12:42               ` file-equal-p Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Po Lu @ 2023-02-16 12:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> It is still one more test, done for everyone.

Is file-equal-p a function called in particularly tight loops?
I think trying to optimize out a test against system-type is premature.

It will otherwise result in file-attributes being called two more times
on the system being tested against.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16 10:35         ` file-equal-p Michael Albinus
@ 2023-02-16 12:35           ` Po Lu
  2023-02-16 12:43             ` file-equal-p Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Po Lu @ 2023-02-16 12:35 UTC (permalink / raw)
  To: Michael Albinus; +Cc: Andreas Schwab, Eli Zaretskii, emacs-devel

Michael Albinus <michael.albinus@gmx.de> writes:

> Andreas Schwab <schwab@suse.de> writes:
>
> Hi,
>
>> On Feb 16 2023, Po Lu wrote:
>>
>>> diff --git a/lisp/files.el b/lisp/files.el
>>> index b0ec6bb09d0..dcd17df166a 100644
>>> --- a/lisp/files.el
>>> +++ b/lisp/files.el
>>> @@ -6360,7 +6360,17 @@ file-equal-p
>>>        (let (f1-attr f2-attr)
>>>          (and (setq f1-attr (file-attributes (file-truename file1)))
>>>  	     (setq f2-attr (file-attributes (file-truename file2)))
>>> -	     (equal f1-attr f2-attr))))))
>>> +             (progn
>>> +               ;; Haiku systems change the file's last access timestamp
>>> +               ;; every time `stat' is called.  Make sure to not compare
>>> +               ;; the timestamps in that case.
>>> +               (when (and (eq system-type 'haiku)
>>> +                          (consp (nthcdr 4 f1-attr))
>>> +                          (consp (nthcdr 4 f2-attr)))
>>> +                 (ignore-errors
>>> +                   (setcar (nthcdr 4 f1-attr) nil)
>>> +                   (setcar (nthcdr 4 f2-attr) nil)))
>>> +	       (equal f1-attr f2-attr)))))))
>>
>> Why does that compare more than the inode and device number?  The other
>> attributes can change any time, if another process accesses the file or
>> modifies the inode between the two calls of file-attribute.
>
> For this we have file-attribute-file-identifier. So it might be
> sufficient to call
>
> (equal (file-attribute-file-identifier f1-attr) (file-attribute-file-identifier f2-attr))
>
> Best regards, Michael.

This looks like the better idea, yes.  Would using that be ok for Emacs
29?  Or is it something for master?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16 12:34             ` file-equal-p Po Lu
@ 2023-02-16 12:42               ` Eli Zaretskii
  2023-02-17  2:40                 ` file-equal-p Po Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-16 12:42 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Thu, 16 Feb 2023 20:34:04 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > It is still one more test, done for everyone.
> 
> Is file-equal-p a function called in particularly tight loops?

I don't know, but punishing everyone for the benefit of a single OS
sounds wrong to me.

> It will otherwise result in file-attributes being called two more times
> on the system being tested against.

Not if you call file-attributes once and store the results in local
variables.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16 12:35           ` file-equal-p Po Lu
@ 2023-02-16 12:43             ` Eli Zaretskii
  0 siblings, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-16 12:43 UTC (permalink / raw)
  To: Po Lu; +Cc: michael.albinus, schwab, emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: Andreas Schwab <schwab@suse.de>,  Eli Zaretskii <eliz@gnu.org>,
>   emacs-devel@gnu.org
> Date: Thu, 16 Feb 2023 20:35:13 +0800
> 
> Michael Albinus <michael.albinus@gmx.de> writes:
> 
> > For this we have file-attribute-file-identifier. So it might be
> > sufficient to call
> >
> > (equal (file-attribute-file-identifier f1-attr) (file-attribute-file-identifier f2-attr))
> >
> > Best regards, Michael.
> 
> This looks like the better idea, yes.  Would using that be ok for Emacs
> 29?  Or is it something for master?

OK to do what?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16 12:42               ` file-equal-p Eli Zaretskii
@ 2023-02-17  2:40                 ` Po Lu
  2023-02-17  6:26                   ` file-equal-p Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Po Lu @ 2023-02-17  2:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Po Lu <luangruo@yahoo.com>
>> Cc: emacs-devel@gnu.org
>> Date: Thu, 16 Feb 2023 20:34:04 +0800
>> 
>> Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> > It is still one more test, done for everyone.
>> 
>> Is file-equal-p a function called in particularly tight loops?
>
> I don't know, but punishing everyone for the benefit of a single OS
> sounds wrong to me.

Why would a single conditional be punishment, though?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-16  1:30 ` file-equal-p Po Lu
  2023-02-16  8:18   ` file-equal-p Eli Zaretskii
@ 2023-02-17  4:50   ` Richard Stallman
  2023-02-17 10:02     ` file-equal-p Andreas Schwab
  1 sibling, 1 reply; 25+ messages in thread
From: Richard Stallman @ 2023-02-17  4:50 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > Someone says that Haiku changes the file access time every time `stat'
  > is called on a file, and as a result `file-equal-p' doesn't work, as it
  > compares the file attributes of both operands.

I'd say that is a bug in Haiku.  The file access time is useless if
examining it automatically changes it.

Or does Haiku offer some other way to examine it without changing it?
If so, can Emacs examine it using that other way?

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17  2:40                 ` file-equal-p Po Lu
@ 2023-02-17  6:26                   ` Eli Zaretskii
  2023-02-17  7:07                     ` file-equal-p Po Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-17  6:26 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Fri, 17 Feb 2023 10:40:59 +0800
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Po Lu <luangruo@yahoo.com>
> >> Cc: emacs-devel@gnu.org
> >> Date: Thu, 16 Feb 2023 20:34:04 +0800
> >> 
> >> Eli Zaretskii <eliz@gnu.org> writes:
> >> 
> >> > It is still one more test, done for everyone.
> >> 
> >> Is file-equal-p a function called in particularly tight loops?
> >
> > I don't know, but punishing everyone for the benefit of a single OS
> > sounds wrong to me.
> 
> Why would a single conditional be punishment, though?

It takes non-zero CPU time.

Anyway, why would you object to a simple request to re-arrange your
change slightly?  I don't understand why such a simple request needs
several messages to discuss, even if you don't consider the request
necessary?  Don't we both have more useful things to invest our time?"



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17  6:26                   ` file-equal-p Eli Zaretskii
@ 2023-02-17  7:07                     ` Po Lu
  2023-02-17  8:32                       ` file-equal-p Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Po Lu @ 2023-02-17  7:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> It takes non-zero CPU time.
>
> Anyway, why would you object to a simple request to re-arrange your
> change slightly?  I don't understand why such a simple request needs
> several messages to discuss, even if you don't consider the request
> necessary?  Don't we both have more useful things to invest our time?"

I was afraid I was missing something more significant about
file-available-p.

Anyway, how's this:

diff --git a/lisp/files.el b/lisp/files.el
index b0ec6bb09d0..5b989902bc3 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6360,7 +6360,18 @@ file-equal-p
       (let (f1-attr f2-attr)
         (and (setq f1-attr (file-attributes (file-truename file1)))
 	     (setq f2-attr (file-attributes (file-truename file2)))
-	     (equal f1-attr f2-attr))))))
+             (progn
+               ;; Haiku systems change the file's last access timestamp
+               ;; every time `stat' is called.  Make sure to not compare
+               ;; the timestamps in that case.
+               (or (equal f1-attr f2-attr)
+                   (when (and (eq system-type 'haiku)
+                              (consp (nthcdr 4 f1-attr))
+                              (consp (nthcdr 4 f2-attr)))
+                     (ignore-errors
+                       (setcar (nthcdr 4 f1-attr) nil)
+                       (setcar (nthcdr 4 f2-attr) nil))
+	             (equal f1-attr f2-attr)))))))))
 
 (defun file-in-directory-p (file dir)
   "Return non-nil if DIR is a parent directory of FILE.



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17  7:07                     ` file-equal-p Po Lu
@ 2023-02-17  8:32                       ` Eli Zaretskii
  2023-02-17 11:05                         ` file-equal-p Po Lu
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-17  8:32 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Fri, 17 Feb 2023 15:07:20 +0800
> 
> Anyway, how's this:
> 
> diff --git a/lisp/files.el b/lisp/files.el
> index b0ec6bb09d0..5b989902bc3 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -6360,7 +6360,18 @@ file-equal-p
>        (let (f1-attr f2-attr)
>          (and (setq f1-attr (file-attributes (file-truename file1)))
>  	     (setq f2-attr (file-attributes (file-truename file2)))
> -	     (equal f1-attr f2-attr))))))
> +             (progn
> +               ;; Haiku systems change the file's last access timestamp
> +               ;; every time `stat' is called.  Make sure to not compare
> +               ;; the timestamps in that case.
> +               (or (equal f1-attr f2-attr)
> +                   (when (and (eq system-type 'haiku)
> +                              (consp (nthcdr 4 f1-attr))
> +                              (consp (nthcdr 4 f2-attr)))
> +                     (ignore-errors
> +                       (setcar (nthcdr 4 f1-attr) nil)
> +                       (setcar (nthcdr 4 f2-attr) nil))
> +	             (equal f1-attr f2-attr)))))))))
>  
>  (defun file-in-directory-p (file dir)
>    "Return non-nil if DIR is a parent directory of FILE.

Fine by me, thanks.

This can go to the emacs-29 branch, if you want.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17  4:50   ` file-equal-p Richard Stallman
@ 2023-02-17 10:02     ` Andreas Schwab
  2023-02-17 12:25       ` file-equal-p Eli Zaretskii
  0 siblings, 1 reply; 25+ messages in thread
From: Andreas Schwab @ 2023-02-17 10:02 UTC (permalink / raw)
  To: Richard Stallman; +Cc: Po Lu, emacs-devel

On Feb 16 2023, Richard Stallman wrote:

> If so, can Emacs examine it using that other way?

The right way to solve the issue is to only compare the inode and device
numbers.  The other attributes (other than the type) can change any time
for unrelated reasons, and do not define the identity of a file.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17  8:32                       ` file-equal-p Eli Zaretskii
@ 2023-02-17 11:05                         ` Po Lu
  0 siblings, 0 replies; 25+ messages in thread
From: Po Lu @ 2023-02-17 11:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Po Lu <luangruo@yahoo.com>
>> Cc: emacs-devel@gnu.org
>> Date: Fri, 17 Feb 2023 15:07:20 +0800
>> 
>> Anyway, how's this:
>> 
>> diff --git a/lisp/files.el b/lisp/files.el
>> index b0ec6bb09d0..5b989902bc3 100644
>> --- a/lisp/files.el
>> +++ b/lisp/files.el
>> @@ -6360,7 +6360,18 @@ file-equal-p
>>        (let (f1-attr f2-attr)
>>          (and (setq f1-attr (file-attributes (file-truename file1)))
>>  	     (setq f2-attr (file-attributes (file-truename file2)))
>> -	     (equal f1-attr f2-attr))))))
>> +             (progn
>> +               ;; Haiku systems change the file's last access timestamp
>> +               ;; every time `stat' is called.  Make sure to not compare
>> +               ;; the timestamps in that case.
>> +               (or (equal f1-attr f2-attr)
>> +                   (when (and (eq system-type 'haiku)
>> +                              (consp (nthcdr 4 f1-attr))
>> +                              (consp (nthcdr 4 f2-attr)))
>> +                     (ignore-errors
>> +                       (setcar (nthcdr 4 f1-attr) nil)
>> +                       (setcar (nthcdr 4 f2-attr) nil))
>> +	             (equal f1-attr f2-attr)))))))))
>>  
>>  (defun file-in-directory-p (file dir)
>>    "Return non-nil if DIR is a parent directory of FILE.
>
> Fine by me, thanks.
>
> This can go to the emacs-29 branch, if you want.

OK, thanks.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17 10:02     ` file-equal-p Andreas Schwab
@ 2023-02-17 12:25       ` Eli Zaretskii
  2023-02-17 12:45         ` file-equal-p tomas
  2023-02-17 13:17         ` file-equal-p Andreas Schwab
  0 siblings, 2 replies; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-17 12:25 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: rms, luangruo, emacs-devel

> From: Andreas Schwab <schwab@linux-m68k.org>
> Cc: Po Lu <luangruo@yahoo.com>,  emacs-devel@gnu.org
> Date: Fri, 17 Feb 2023 11:02:48 +0100
> 
> On Feb 16 2023, Richard Stallman wrote:
> 
> > If so, can Emacs examine it using that other way?
> 
> The right way to solve the issue is to only compare the inode and device
> numbers.  The other attributes (other than the type) can change any time
> for unrelated reasons, and do not define the identity of a file.

That depends on the semantics of "files are equal".  If the issue is
only whether two file names point to the same file's data, then yes,
using file-attribute-file-identifier is TRT.  But that is not the only
possible semantics of these tests.  It is therefore up to the
application to decide which API to use, IMO.

Of course, as long as the file is identified only by its name, race
condition is possible even if we only compare the inode and the device
number.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17 12:25       ` file-equal-p Eli Zaretskii
@ 2023-02-17 12:45         ` tomas
  2023-02-17 13:17         ` file-equal-p Andreas Schwab
  1 sibling, 0 replies; 25+ messages in thread
From: tomas @ 2023-02-17 12:45 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]

On Fri, Feb 17, 2023 at 02:25:38PM +0200, Eli Zaretskii wrote:
> > From: Andreas Schwab <schwab@linux-m68k.org>
> > Cc: Po Lu <luangruo@yahoo.com>,  emacs-devel@gnu.org
> > Date: Fri, 17 Feb 2023 11:02:48 +0100
> > 
> > On Feb 16 2023, Richard Stallman wrote:
> > 
> > > If so, can Emacs examine it using that other way?
> > 
> > The right way to solve the issue is to only compare the inode and device
> > numbers.  The other attributes (other than the type) can change any time
> > for unrelated reasons, and do not define the identity of a file.
> 
> That depends on the semantics of "files are equal".  If the issue is
> only whether two file names point to the same file's data, then yes,
> using file-attribute-file-identifier is TRT.

This is how I read `file-equal-p''s docstring [1] (coming from Lisp,
I'd called it `file-eq-p', but hey :-)

>                                              But that is not the only
> possible semantics of these tests.  It is therefore up to the
> application to decide which API to use, IMO.
> 
> Of course, as long as the file is identified only by its name, race
> condition is possible even if we only compare the inode and the device
> number.

Identity is always difficult in a mutable world, yes.

Cheers

[1] Return non-nil if files FILE1 and FILE2 name the same file.
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17 12:25       ` file-equal-p Eli Zaretskii
  2023-02-17 12:45         ` file-equal-p tomas
@ 2023-02-17 13:17         ` Andreas Schwab
  2023-02-18 12:25           ` file-equal-p Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Andreas Schwab @ 2023-02-17 13:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, luangruo, emacs-devel

On Feb 17 2023, Eli Zaretskii wrote:

> That depends on the semantics of "files are equal".  If the issue is
> only whether two file names point to the same file's data, then yes,
> using file-attribute-file-identifier is TRT.  But that is not the only
> possible semantics of these tests.

What are those other semantics?

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-17 13:17         ` file-equal-p Andreas Schwab
@ 2023-02-18 12:25           ` Eli Zaretskii
  2023-02-18 14:04             ` file-equal-p Andreas Schwab
  0 siblings, 1 reply; 25+ messages in thread
From: Eli Zaretskii @ 2023-02-18 12:25 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: rms, luangruo, emacs-devel

> From: Andreas Schwab <schwab@linux-m68k.org>
> Cc: rms@gnu.org,  luangruo@yahoo.com,  emacs-devel@gnu.org
> Date: Fri, 17 Feb 2023 14:17:48 +0100
> 
> On Feb 17 2023, Eli Zaretskii wrote:
> 
> > That depends on the semantics of "files are equal".  If the issue is
> > only whether two file names point to the same file's data, then yes,
> > using file-attribute-file-identifier is TRT.  But that is not the only
> > possible semantics of these tests.
> 
> What are those other semantics?

The simplest one is when the caller wants to check whether all of the
attributes of two sets are identical, for example in order to see if
the file was accessed since the last check.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: file-equal-p
  2023-02-18 12:25           ` file-equal-p Eli Zaretskii
@ 2023-02-18 14:04             ` Andreas Schwab
  0 siblings, 0 replies; 25+ messages in thread
From: Andreas Schwab @ 2023-02-18 14:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, luangruo, emacs-devel

On Feb 18 2023, Eli Zaretskii wrote:

> The simplest one is when the caller wants to check whether all of the
> attributes of two sets are identical, for example in order to see if
> the file was accessed since the last check.

That's not what the function can do.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2023-02-18 14:04 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87a61es8fh.fsf.ref@yahoo.com>
2023-02-16  1:30 ` file-equal-p Po Lu
2023-02-16  8:18   ` file-equal-p Eli Zaretskii
2023-02-16  8:43     ` file-equal-p Po Lu
2023-02-16  8:57       ` file-equal-p Eli Zaretskii
2023-02-16  9:59         ` file-equal-p Po Lu
2023-02-16 11:52           ` file-equal-p Eli Zaretskii
2023-02-16 12:34             ` file-equal-p Po Lu
2023-02-16 12:42               ` file-equal-p Eli Zaretskii
2023-02-17  2:40                 ` file-equal-p Po Lu
2023-02-17  6:26                   ` file-equal-p Eli Zaretskii
2023-02-17  7:07                     ` file-equal-p Po Lu
2023-02-17  8:32                       ` file-equal-p Eli Zaretskii
2023-02-17 11:05                         ` file-equal-p Po Lu
2023-02-16  9:15       ` file-equal-p Andreas Schwab
2023-02-16  9:58         ` file-equal-p Po Lu
2023-02-16 10:35         ` file-equal-p Michael Albinus
2023-02-16 12:35           ` file-equal-p Po Lu
2023-02-16 12:43             ` file-equal-p Eli Zaretskii
2023-02-17  4:50   ` file-equal-p Richard Stallman
2023-02-17 10:02     ` file-equal-p Andreas Schwab
2023-02-17 12:25       ` file-equal-p Eli Zaretskii
2023-02-17 12:45         ` file-equal-p tomas
2023-02-17 13:17         ` file-equal-p Andreas Schwab
2023-02-18 12:25           ` file-equal-p Eli Zaretskii
2023-02-18 14:04             ` file-equal-p Andreas Schwab

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).