in reply to Re: unlink & rename in Win32
in thread unlink & rename in Win32
sub changelog { if($GMS->getsetting('OTHER','LOGCLEAR') > param("NOWTIME")){ viewlog("Error: Time-Date mismatch."); exit; } my $filename = $GMS->getsetting('FILE','MEMBERDIRL').'/GMS'; open(logfile,"$filename.log") or $GMS->dienice("Unable to open log +file!"); flock(logfile,2) if($GMS->getsetting('OTHER','FLOCK')); my $length = scalar(@{[<logfile>]})-1; seek(logfile,0,0); my %lines; for(my $i = 1; $i <= $length+1; $i++){ $lines{$i} = 1 if(param("LINE$i")); } open(tempfile,">$filename.tmp") or $GMS->dienice("Unable to open te +mporary file!"); flock(tempfile,2) if($GMS->getsetting('OTHER','FLOCK')); seek(tempfile,0,0); my $count = 0; while(my $line = <logfile>){ $count++; if($lines{$count}){ next; }else{ print STDERR "$count kept\n"; } print tempfile $line; } close(tempfile); close(logfile); rename("$filename.log","$filename.bak") or $GMS->dienice(); rename("$filename.tmp","$filename.log") or $GMS->dienice(); unlink("$filename.bak") or $GMS->dienice(); $GMS->changesetting('OTHER','LOGCLEAR',time); #The GMS object actually does have a filehandle for the 'logfile' i +n the object #however, I have tried manually closing it and there was no differe +nce. $GMS->logaction("Removed elements from log file"); viewlog("Changes sucessful!"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: unlink & rename in Win32
by IlyaM (Parson) on Dec 02, 2001 at 16:41 UTC | |
by rob_au (Abbot) on Dec 02, 2001 at 16:53 UTC |