Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File::Copy won't copy *.h files

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
0
0
US
I wrote a script to move ImageMagick module into chroot, worked fine except that refused to copy any of the *.h files. Why not?
Directory and file permissions allow it and I ran script as root.

Code:
#!/usr/bin/perl
use warnings;
#use strict;
use diagnostics;

#Image Magick file copier to suexec_chroot

use File::Copy;
use lib qw(/var/[URL unfurl="true"]www/htdocs/users/visionsbykarl.com/cgi/);[/URL]

my @files;
my $sourcefile;
print "Content-type: text/plain \n\n"; #The header

open(IN,"<ImageMagickfiles") || print ("could not open");
	while (<IN>) {

my $filetobecopied=$_;
chomp $filetobecopied;
my $newfile = "/var/[URL unfurl="true"]www$filetobecopied";[/URL]

print "$filetobecopied\n";
print $newfile ."\n";
copy($filetobecopied, $newfile) or warn "File really cannot be copied.";
print "file copied:   $filetobecopied --> $newfile  \n\n";
}
	close(IN);
print "OK";
 
Permissions?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
my $newfile = "/var/
should this not be

my $newfile = "/var/www/$filetobecopied";


Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
the files are root:daemon with r--r--r--
the directories are from rwxr-xr-x to rwxrwxr-x or rwxr-----

All of the other files copied fine
 
No, the file containing the files already has the / in front
But having it like you suggested was my first mistake :)
 
copy the .h files to .htm, and see if they copy, it's not likely, but there could be a bug in Fily::Copy

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
instead of

copy($filetobecopied, $newfile) or warn "File really cannot be copied.";

try

copy($filetobecopied, $newfile) or die "$!";

also check your server error log files to see if there's more information there

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I get:

Uncaught exception from user code:
File really cannot be copied. No such file or directory at ./ImageMagickMover.cgi line 24, <IN> line 1.
at ./ImageMagickMover.cgi line 24

But I already copied these files by hand so they do exist!
 
does it need the full path?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Yes, but I'm using a file that contains the full paths from the package contents page. I tried changing the script to save the copy with "tm" added. didn't help and just realized that the problem therefore HAS to be in opening those files ending in .h, not in writing the new file. I'm very puzzled by this problem, can't see any reason why some files copy fine, but these won't. I want to use this script from now on to move modules into chroot, would be nice to remove need to manually add some files
 
Did you do this part?

copy($filetobecopied, $newfile) or die "$!";

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Yes I posted results above.

Uncaught exception from user code:
File really cannot be copied. No such file or directory at ./ImageMagickMover.cgi line 24, <IN> line 1.
at ./ImageMagickMover.cgi line 24

I'm not running this through httpd, since script can't get outside of chroot folders to get files
 
it seems weird that the error message says ./ but you are providing the full path.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I would add a die statement at the end of the open rather than a print statement.

Also, are you reading a data file or a directory with your open statement?
 
are you opening a file or a directory?

Code:
open(IN,"<ImageMagickfiles") || print ("could not open");

if a directory you should use opendir and readdir. But that does not seem to be the root of your problem because you say other files are copied with the code you posted.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I found another answer to my problem. I changed to File::Copy::Recursive which copies files and directories recursively easily

This works perfectly including *.h files:
Code:
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;

#  File copier to suexec_chroot directories

use File::Copy::Recursive;

open(IN,"<FileList") || print ("could not open $!");
	while (<IN>) {
	chomp $_;
	my $orig=$_;
	my $new="/var/[URL unfurl="true"]www$_";[/URL]
	print "orig=$orig\n";
	print "New=$new\n";
	unless (my($num_of_files_and_dirs,$num_of_dirs,$depth_traversed) = &File::Copy::Recursive::rcopy($orig,$new)){
	warn "copying failed  $!";
	}
	}
print "\nOK";

I would still like to know why File::Copy fails but I think it is a bug. I will pass this on to the maintainer
 
I'd write a specific sample script to prove it's an issue, try it on Linux and windows, before contacting the maintainer

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
The problem you have is really in your code, not File::Copy; Example:

<quote>
[ryagatich@nemesis ~/code/copy]$ find
.
./src
./src/test1.c
./src/test1.h
./dst
./copy.pl
[ryagatich@nemesis ~/code/copy]$ perl copy.pl
[ryagatich@nemesis ~/code/copy]$ find
.
./src
./src/test1.c
./src/test1.h
./dst
./dst/test1.c
./dst/test1.h
./copy.pl
[ryagatich@nemesis ~/code/copy]$ cat copy.pl
#!/usr/bin/perl -w

use strict;
use File::Copy;
use IO::Dir;
my ($s, $d) = ('src', 'dst');
my $dh = IO::Dir->new($s);
while (my $fn = $dh->read) {
next if ($fn =~ /^\.\.?$/);
&File::Copy::copy($s . '/' . $fn, $d . '/' . $fn);
}
$dh->close;

[ryagatich@nemesis ~/code/copy]$
</quote>


As you can see from the above test, the file is successfully copied.

In your code, add to your warning the reason why it failed (special var: $!) - this may help in diagnosis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top