Easier test for "regular file"?

Discussion in 'Perl Misc' started by bill, May 18, 2004.

  1. bill

    bill Guest

    I'm writing a package that needs to interact with cvs. For what
    I want to do I need the ability to determine whether or not a file
    is considered "regular" by cvs. According to the cvs docs:

    Special Files

    In normal circumstances, CVS works only with regular files.
    Every file in a project is assumed to be persistent; it must be
    possible to open, read and close them; and so on...

    Therefore, I have

    sub is_regular {
    local $_ = shift; # argument is a filename

    # brute-force elimination
    !(-b||-c||-d||-l||-p||-S||-t);
    }

    (Note: having is_regular return -f --instead of the above--would
    be no good; for example -f evaluates to 1 if $_ is the name of a
    symlink.)

    Is there an easier way (at least easier on the eyes) to test for
    "regularity" than the brute-force elimination expression above?

    Thanks a bunch,

    -bill
     
    bill, May 18, 2004
    #1
    1. Advertising

  2. bill

    Ben Morrow Guest

    Quoth bill <>:
    >
    > I'm writing a package that needs to interact with cvs. For what
    > I want to do I need the ability to determine whether or not a file
    > is considered "regular" by cvs.
    >
    > sub is_regular {
    > local $_ = shift; # argument is a filename
    >
    > # brute-force elimination
    > !(-b||-c||-d||-l||-p||-S||-t);
    > }
    >
    > (Note: having is_regular return -f --instead of the above--would
    > be no good; for example -f evaluates to 1 if $_ is the name of a
    > symlink.)


    Yes, but that is the only case, so

    not -l and -f _;

    is what you want (the tests must come in this order: -f and not -l _
    would do a stat(2) not an lstat(2) and thus not catch symlinks).

    OTOH, are you sure that a symlink to a regular file is unacceptable:
    what does cvs do about following symlinks?

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    /Alcestis/) [ flame, and falls out of sight. ]
     
    Ben Morrow, May 18, 2004
    #2
    1. Advertising

  3. bill

    bill Guest

    In <c8bqu7$f96$> Ben Morrow <> writes:

    >Quoth bill <>:
    >>
    >> I'm writing a package that needs to interact with cvs. For what
    >> I want to do I need the ability to determine whether or not a file
    >> is considered "regular" by cvs.
    >>
    >> sub is_regular {
    >> local $_ = shift; # argument is a filename
    >>
    >> # brute-force elimination
    >> !(-b||-c||-d||-l||-p||-S||-t);
    >> }
    >>
    >> (Note: having is_regular return -f --instead of the above--would
    >> be no good; for example -f evaluates to 1 if $_ is the name of a
    >> symlink.)


    >Yes, but that is the only case, so


    >not -l and -f _;


    >is what you want (the tests must come in this order: -f and not -l _
    >would do a stat(2) not an lstat(2) and thus not catch symlinks).


    Great. Thanks!

    >OTOH, are you sure that a symlink to a regular file is unacceptable:
    >what does cvs do about following symlinks?


    According to the docs, "cvs import" reports it whenever it encounters
    a symlink, but otherwise it ignores them. As for the rest, I don't
    know of any "official" description of cvs's behavior, but in my
    experience "cvs commit" replaces symlinks with their targets, which
    is usually unacceptable. As for hard links, both import and commit
    replace hard links with distinct files containing identical copies
    of the data originally associated with the hard links.

    -bill
     
    bill, May 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Norman Ackroyd
    Replies:
    1
    Views:
    551
  2. Kathy Burke
    Replies:
    0
    Views:
    343
    Kathy Burke
    Jul 31, 2003
  3. Raterus
    Replies:
    1
    Views:
    2,256
    Srinivas
    Feb 13, 2004
  4. PiotrO
    Replies:
    0
    Views:
    308
    PiotrO
    May 2, 2004
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    726
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page