unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Andrew Tropin <andrew@trop.in>
To: Maxime Devos <maximedevos@telenet.be>, 54762@debbugs.gnu.org
Subject: [bug#54762] [PATCH] home: symlink-manager: Use no-follow version of file-exists?.
Date: Thu, 07 Apr 2022 20:01:18 +0300	[thread overview]
Message-ID: <87bkxc6d5t.fsf@trop.in> (raw)
In-Reply-To: <67cab598e57ecf7cf930d4b2d0568fd2f2f6f95d.camel@telenet.be>

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

On 2022-04-07 14:28, Maxime Devos wrote:

> Andrew Tropin schreef op do 07-04-2022 om 11:22 [+0300]:
>> +         (define (no-follow-file-exists? file) 
>> +           "Return #t if file exists, even if it's a dangling
>> symlink."
>> +           (or (file-exists? file)
>> +               (and=> (false-if-exception (lstat file))
>> +                      (lambda (x)
>> +                        (equal? (stat:type x) 'symlink)))))
>
> Can't this be simplified to
>
>   (define (no-follow-file-exists? file)
>     (false-if-exception (lstat file)))
>

Idk how file-exists? works internally, but still expect it to be more
efficient than lstat.  That's why I decided to use lstat only as a
"fallback" option in `or` statement.

> ?  Also, do you want to ignore _all_ exceptions, or only the ENOENT and
> maybe ENOTDIR system-error?
>
> (catch 'system-error
>   (lambda () (lstat file) #t)
>   (lambda e
>     (if its-a-ENOFILE
>         #f
>         (apply throw e))))
>
> More concretely, why is ENOMEM, ENAMETOOLONG and EACCESS ignored here?

You are right, we are interested only in ENOENT here.  AFAIK, ENOMEM
shouldn't happen here, but some other can, still we do not handle them
and make function behave the same way as file-exists? do and just return
#f in such cases.  However, I'm not sure if file-exists? is a good
example to follow.

Anyway in current implementation handling other codes in
no-follow-file-exists? will not save the day, in case of EACCESS it
doesn't really matter if it will be thrown during the check of existence
or during creation of symlink.  But we probably can later rework the
whole symlinking process: check that we have premissions to all files,
we are interested in, and only after that cleanup, backup and symlink.

>
> Greetings,
> Maxime.

-- 
Best regards,
Andrew Tropin

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

  reply	other threads:[~2022-04-07 17:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07  8:22 [bug#54762] [PATCH] home: symlink-manager: Use no-follow version of file-exists? Andrew Tropin
2022-04-07 12:28 ` Maxime Devos
2022-04-07 17:01   ` Andrew Tropin [this message]
2022-04-07 18:17     ` Maxime Devos
2022-04-07 18:21     ` Maxime Devos
2022-04-08  4:23       ` Andrew Tropin
2022-04-09 21:57         ` bug#54762: " Ludovic Courtès
2022-04-11  5:26           ` [bug#54762] " Andrew Tropin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bkxc6d5t.fsf@trop.in \
    --to=andrew@trop.in \
    --cc=54762@debbugs.gnu.org \
    --cc=maximedevos@telenet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.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).