T
Tim McDaniel
My apologies for asking a Cygwin- or Windows-specific question here,
but it's also Perl-specific, and I'm not sure of a better
easy-to-access place.
I looked in perlfaq5 and didn't see it discussed there, possibly
because it's a Cygwin or Windows problem in particular -- but this HAS
to be a common problem. I tried some Googling, but it's hard to
search for "w", and I couldn't think of effective search terms.
I'm using a pretty recent Cygwin, but I don't know how to find out a
version number or date. "cd"ed into an NTFS partition. Environment
variable CYGWIN is "tty ntsec".
The current directory is owned by group Administrators; my user ID is
in group Administrators; group Administrators has full control. So I
can do any regular commands that create or delete files (Cygwin touch,
CMD.EXE copy, anything).
But
perl -e 'print(-w "." ? "yes\n" : "no\n")'
prints "no", and the same for -r and -x.
Possibly related to "ls -ld" outputting this:
drwx------+ 30 ???????? none 0 Jan 15 11:44 .
I noticed this when I couldn't get File::Temp to work with DIR=>'.'
[footnote 2], because of its code
# Check that the parent directories exist
# Do this even for the case where we are simply returning a name
# not a file -- no point returning a name that includes a directory
# that does not exist or is not writable
unless (-d $parent) {
${$options{ErrStr}} = "Parent directory ($parent) is not a directory";
return ();
}
unless (-w $parent) {
${$options{ErrStr}} = "Parent directory ($parent) is not writable\n";
return ();
}
[footnote 1]
Question 1: is there any way I can get Perl's -r / -w / -x functions
to work? Is this indeed an FAQ question, or should I actually file a
bug report with the Cygwin group?
Question 2: Is there another module that's shipped with Perl that I
could use instead of File::Temp? I don't know of a way to tell all
the modules that are installed. (I'd really prefer not to depend on
yet another module needing to be installed.) IO::File::new_tmpfile()
doesn't take a directory name [2]. POSIX's
char * tempnam(const char *tmpdir, const char *prefix)
is not implemented in module POSIX::...
I guess I'll just adapt the code from perlfaq5 ...
Question 3: ... but why is it wrapped in a BEGIN block?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1] I consider that a design flaw. I believe that the best way to
test that an operation will succeed is simply to try to do it, and
catch the failure. (When the operation indicates all errors, and when
it is atomic, either succeeding completely or failing with no
residure.)
[2] There are reasons that I don't use TMPDIR, TEMP, or TMP. They are
irrelevant to this problem. Really. ...
.... if you insist: I often run the Perl program outside of a Cygwin
window. Even when TMPDIR is set in Windows syntax as C:\tmp, on
startup Perl transmogrifies it to /tmp (or whatever, per cygpath -u).
The Perl program calls non-Cygwin-aware programs, so they have to get
non-Cygwin paths like "e:\foo\bar" instead of "/CM/foo/bar". Since
the Perl program is running in a cmd.exe window, Cygwin programs are
not in the Path ... meaning I can't just run "cygpath -w". I don't
want to hard-code Path directories into the script.
But "." is a directory name that works in both Cygwin and non-Cygwin.
It's not much of a stretch to insist that they run the program in a
writable directory ... as long as Perl realizes that it's writable,
dammit!!1!
but it's also Perl-specific, and I'm not sure of a better
easy-to-access place.
I looked in perlfaq5 and didn't see it discussed there, possibly
because it's a Cygwin or Windows problem in particular -- but this HAS
to be a common problem. I tried some Googling, but it's hard to
search for "w", and I couldn't think of effective search terms.
I'm using a pretty recent Cygwin, but I don't know how to find out a
version number or date. "cd"ed into an NTFS partition. Environment
variable CYGWIN is "tty ntsec".
The current directory is owned by group Administrators; my user ID is
in group Administrators; group Administrators has full control. So I
can do any regular commands that create or delete files (Cygwin touch,
CMD.EXE copy, anything).
But
perl -e 'print(-w "." ? "yes\n" : "no\n")'
prints "no", and the same for -r and -x.
Possibly related to "ls -ld" outputting this:
drwx------+ 30 ???????? none 0 Jan 15 11:44 .
I noticed this when I couldn't get File::Temp to work with DIR=>'.'
[footnote 2], because of its code
# Check that the parent directories exist
# Do this even for the case where we are simply returning a name
# not a file -- no point returning a name that includes a directory
# that does not exist or is not writable
unless (-d $parent) {
${$options{ErrStr}} = "Parent directory ($parent) is not a directory";
return ();
}
unless (-w $parent) {
${$options{ErrStr}} = "Parent directory ($parent) is not writable\n";
return ();
}
[footnote 1]
Question 1: is there any way I can get Perl's -r / -w / -x functions
to work? Is this indeed an FAQ question, or should I actually file a
bug report with the Cygwin group?
Question 2: Is there another module that's shipped with Perl that I
could use instead of File::Temp? I don't know of a way to tell all
the modules that are installed. (I'd really prefer not to depend on
yet another module needing to be installed.) IO::File::new_tmpfile()
doesn't take a directory name [2]. POSIX's
char * tempnam(const char *tmpdir, const char *prefix)
is not implemented in module POSIX::...
I guess I'll just adapt the code from perlfaq5 ...
Question 3: ... but why is it wrapped in a BEGIN block?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1] I consider that a design flaw. I believe that the best way to
test that an operation will succeed is simply to try to do it, and
catch the failure. (When the operation indicates all errors, and when
it is atomic, either succeeding completely or failing with no
residure.)
[2] There are reasons that I don't use TMPDIR, TEMP, or TMP. They are
irrelevant to this problem. Really. ...
.... if you insist: I often run the Perl program outside of a Cygwin
window. Even when TMPDIR is set in Windows syntax as C:\tmp, on
startup Perl transmogrifies it to /tmp (or whatever, per cygpath -u).
The Perl program calls non-Cygwin-aware programs, so they have to get
non-Cygwin paths like "e:\foo\bar" instead of "/CM/foo/bar". Since
the Perl program is running in a cmd.exe window, Cygwin programs are
not in the Path ... meaning I can't just run "cygpath -w". I don't
want to hard-code Path directories into the script.
But "." is a directory name that works in both Cygwin and non-Cygwin.
It's not much of a stretch to insist that they run the program in a
writable directory ... as long as Perl realizes that it's writable,
dammit!!1!