grinder has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks, I am rewriting a shell script in Perl. The shell script calls find(1) with the -mount switch, to stop it crossing filesystem boundaries.

I'm in the middle of my wanted() sub for the usual suspect and I don't know how to mimic the -mount behaviour. I can think of two ways but I baulk at implementing them.

It there some obvious (read: elegant) way in Perl to determine whether a directory is a mount point, short of either parsing /etc/mnttab (sigh) or the output of df (eeeeww) ?


--
g r i n d e r

Replies are listed 'Best First'.
Re: find(1) and its -mount switch
by arhuman (Vicar) on Apr 13, 2001 at 16:37 UTC
    Using man find I found that -mount is an alias for -xdev So I tried :
    find2perl / -xdev which gave me :
    #! /usr/bin/perl -w eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; #$running_under_some_shell use strict; use File::Find (); # Set the variable $File::Find::dont_use_nlink if you're using AFS, # since AFS cheats. # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; # Traverse desired filesystems File::Find::find({wanted => \&wanted}, '/'); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && !($File::Find::prune |= ($dev != $File::Find::topdev)); }

    Hope this helps...


    "Only Bad Coders Badly Code In Perl" (OBC2IP)