unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#34860: Probing broken symlinks always involves errors
@ 2019-03-14 19:50 Tim Gesthuizen
  2019-04-10 19:22 ` Mark H Weaver
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Gesthuizen @ 2019-03-14 19:50 UTC (permalink / raw)
  To: 34860

Hi,
I wrote a little application that tries to probe whether a symlink
exists. The `stat` function has an undocumented optional parameter that
lets stat return #f when the file does not exist. With this argument one
can probe for any files excluding broken symlinks.
lstat does not offer this argument. Therefore I needed to use
guard-expressions around lstat to probe for broken symlinks.

So probing broken symlinks relies on errors in the control flow and is
not straight forward. Maybe we should add the optional argument that
`stat` has and document the arguments for both commands.

I am using guile 2.2.4.

Tim.





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

* bug#34860: Probing broken symlinks always involves errors
  2019-03-14 19:50 bug#34860: Probing broken symlinks always involves errors Tim Gesthuizen
@ 2019-04-10 19:22 ` Mark H Weaver
  2019-04-11 18:05   ` Tim Gesthuizen
  0 siblings, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2019-04-10 19:22 UTC (permalink / raw)
  To: Tim Gesthuizen; +Cc: 34860

Hi Tim,

Tim Gesthuizen <tim.gesthuizen@yahoo.de> writes:

> I wrote a little application that tries to probe whether a symlink
> exists. The `stat` function has an undocumented optional parameter that
> lets stat return #f when the file does not exist. With this argument one
> can probe for any files excluding broken symlinks.
> lstat does not offer this argument. Therefore I needed to use
> guard-expressions around lstat to probe for broken symlinks.
>
> So probing broken symlinks relies on errors in the control flow and is
> not straight forward.

I would suggest using 'false-if-exception', which is documented in the
manual:

  (false-if-exception (lstat file-name))

That seems fairly straightforward and readable, no?

I'm not sure that errors in the control flow is necessarily something
that we need to avoid in cases like this.  It's true that there's some
minor expense involved in handling the exception, but I suspect it's
lost in the noise compared with the expense of the 'lstat' system call
itself.

Do you see a practical problem with this approach?

> Maybe we should add the optional argument that `stat` has and document
> the arguments for both commands.

I'm not strongly opposed to the idea, but it raises the question of what
to do with the corresponding C API function 'scm_lstat'.  We certainly
can't change the number of arguments to 'scm_lstat' in the 2.2.x series,
because that would break ABI compatibility.  We could change it in the
next release series, but that would require source-level changes in any
code that uses 'scm_lstat'.

Alternatively, we could keep 'scm_lstat' unchanged, and add a new
internal C function with the optional argument, bound to Scheme 'lstat'.

Anyway, I'm inclined to simply suggest using 'false-if-exception'.

What do you think?

Regardless, thanks for bringing my attention to the fact that 'scm_stat'
is incorrectly documented in the manual.  It asserts that there's only
one argument to that function, but in fact there are now two.  That's
definitely a bug.

     Regards,
       Mark





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

* bug#34860: Probing broken symlinks always involves errors
  2019-04-10 19:22 ` Mark H Weaver
@ 2019-04-11 18:05   ` Tim Gesthuizen
  2019-06-30 19:54     ` Ludovic Courtès
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Gesthuizen @ 2019-04-11 18:05 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: 34860

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi Mark,

Mark H Weaver writes:
> Anyway, I'm inclined to simply suggest using 'false-if-exception'.
>
> What do you think?

I'm fine with this solution. My point was more about lowering the entry
barrier for beginners than performance.
If the change breaks ABI it is probably just not worth it.

- From my point of view we can close the ticket unless you want to keep it
open until the documentation for stat is fixed.

Tim.
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEKUiC5+8BRKEri5fa0uWPaa77GdUFAlyvgdUACgkQ0uWPaa77
GdWvVQf/QdJ6Mze6jdx3qeFNjcq0hJCdkjykjWQal2m2eFNan+9RgrWUo/oGmJxq
9kVrckRE8lSH0Lh0jy5vhVtf4kBLcEKMB3oHBg7SM/w10nYsqkeZx+hV+MQkKQ3O
FomSddVDwa1R2aCHOJ55anHehvY5ICe2iQnASRPV4S/1h29b4cqg6W8OoKAiB2XR
GP7xfJ2s9y1IUm/0zSaAwpzr+CXcsplZVDgKcERo46/lfovFVsynhFJqNuU6ulBF
QJZAZyohH4SYiPQ21zq4r95WAr1UUfm8awJJuv5zgWx7wTcipUomXyINdnV6jEdT
bUGnNNOqpmhzzYuP0j+lI3yRqYb2/g==
=JSqx
-----END PGP SIGNATURE-----





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

* bug#34860: Probing broken symlinks always involves errors
  2019-04-11 18:05   ` Tim Gesthuizen
@ 2019-06-30 19:54     ` Ludovic Courtès
  0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2019-06-30 19:54 UTC (permalink / raw)
  To: Tim Gesthuizen; +Cc: 34860-done

Hi Tim,

Tim Gesthuizen <tim.gesthuizen@yahoo.de> skribis:

> Mark H Weaver writes:
>> Anyway, I'm inclined to simply suggest using 'false-if-exception'.
>>
>> What do you think?
>
> I'm fine with this solution. My point was more about lowering the entry
> barrier for beginners than performance.
> If the change breaks ABI it is probably just not worth it.
>
> From my point of view we can close the ticket unless you want to keep it
> open until the documentation for stat is fixed.

Commit 63f54a7bc6adbc0f1b397872fb7eb96e84967ff1 updates the manual to
document the optional parameter of ‘stat’.

I think we can close the bug now.  :-)

Thanks,
Ludo’.





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

end of thread, other threads:[~2019-06-30 19:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14 19:50 bug#34860: Probing broken symlinks always involves errors Tim Gesthuizen
2019-04-10 19:22 ` Mark H Weaver
2019-04-11 18:05   ` Tim Gesthuizen
2019-06-30 19:54     ` Ludovic Courtès

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).