finding ....

Pixel pixel@mandrakesoft.com
20 Mar 2002 02:37:03 +0100


Lennart Augustsson <lennart@augustsson.net> writes:

> Just because many applications use this doesn't make it safe or good.
> Presumably you are testing for the existence of the file to do something
> to it (read, create, delete...).  It's better to do the operation you want to
> do and have it fail if the file is missing (or existing if you create).  You
> then just have to handle the exception (that part is already in H98) or
> proceed with the normal path.  I claim the code simpler this way and you
> avoid any race conditions.

I said real-world pbs ;p

WARNING, perl below!

- checking if devfs is mounted in /dev: -e "/dev/.devfsd"
- checking wether there is cdrom drive with devfs: -e "/dev/cdroms/cdrom0"
- looking for a file in a PATH-like:
  if ($f !~ m|/|) { -e "$_/$f" and $f = "$_/$f", last foreach @icon_paths }
- 
  if (-e "$f.gz") {
     # ... the wanted file is gzip'ed, doing whatever is needed
  }

- 
  -x "/bin/sh" or die "cannot open shell - /bin/sh doesn't exist";
  fork and return;
  # doing things
  # now, and only now exec'ing
  exec "/bin/sh"

-
  if (! -e '/usr/sbin/showmount') {
      my $pkg = 'nfs-utils-clients';
      $in->ask_okcancel('', _("The package %s needs to be installed. Do you want to install it?", $pkg), 1) or return;
      $in->do_pkgs->install($pkg);
  }

If you want some more, just ask ;)