Easier test for "regular file"?

B

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

Ben Morrow

Quoth bill said:
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
 
B

bill

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top