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

Trying to delete some temp files from a set of servers Running it semed to work but now the unlink returns 1 which is good but the file is actually not deleted. The files are hidden but read/write and are on windows 2000 servers I would expect a 0 if it cannot delete. Any ideas?
foreach (<SERVERLIST>) { my $servername=$_; chomp($servername); if (!($servername=~/^#/)&& ($servername)) {## no #'s and not empty do this my $pathtocache='//'.$servername.'/'.'e$'; opendir(DIR, $pathtocache); my(@files) = grep {/^VSPCache/i } readdir(DIR); ## give m +e a list of only VSPCache files closedir(DIR); ## close directory handler foreach (@files) { my $filename=$_; my $file2del=$pathtocache.'/'.$filename; my $unlinkstat=unlink($file2del); if ($unlinkstat==0) { ## add unsuccessful delete to error array list to be + sent out later push @errlist, $file2del."\n"; } } } } close(SERVERLIST);

Replies are listed 'Best First'.
Re: unlink return code success but not deleted
by Abigail-II (Bishop) on Feb 25, 2004 at 15:07 UTC
    I see you have an opendir whose return value you don't check. Perhaps the opendir fails. Then readdir returns an empty list. This results in no files being unlinked, and could explain the results you are seeing.

    Or perhaps you are unlinking different files than you think you are. I'd suggest adding some debugging statements around the unlink.

    Abigail

Re: unlink return code success but not deleted
by rinceWind (Monsignor) on Feb 25, 2004 at 16:10 UTC
    I hope you get to the bottom of this, as it would rather preclude the portable recursive deletion technique detailed in this node.

    One of the replies mentions that unlink under some flavours of Windows return success when the file cannot immediately be deleted because of a sharing violation. The delete request is queued up to happen when the share gets closed, and unlink returns success in the mean time (annoyingly, the file is still there and its parent directory cannot be deleted). Could this be what is happening in your case?

    --
    I'm Not Just Another Perl Hacker

Re: unlink return code success but not deleted
by ysth (Canon) on Feb 25, 2004 at 16:29 UTC
    What perl are you running (version and vendor)? Are the files possibly open? Do they automatically go away when they get closed? Do any of the unlinks succeed in immediately deleting a file?
Re: unlink return code success but not deleted
by bengmau (Beadle) on Feb 25, 2004 at 15:00 UTC
    BTW these files are over 100MB each. Is it timing out?