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

Can anyone come up with a reason as to why rename and unlink come up with the following error under win32 for files that the program itself created?

"Permission denied"

I did a quick search and I couldn't see anything on this subject... if it was already posted please just forward me toward it.

Thanks


-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate

"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS

Replies are listed 'Best First'.
Re: unlink & rename in Win32
by growlf (Pilgrim) on Dec 01, 2001 at 10:54 UTC
    Could you post a snippet of the offending code, perhaps?

    *G*
      Certainly:

      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!"); }


      FYI: This is run under 'strict'
      Now, this code actually has one of the filehandles still open, however I had tried manually closing it with no effect...

      This is only a bit of the code... but I didn't think anyone would want me to send over 2000 lines of code.

      Does this clear anything up?


      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

        I'm not sure but AFAIK on some OSes you should release locks creates with flock before closing filehandle. That is add
        flock(tempfile, 4); flock(logfile, 4);
        before closing these filehandles.

        P.S. You should avoid using numbers for constants as it is hard to read and is not fail proof. Use symbol names. use Fcntl ':flock' defines for you LOCK_SH, LOCK_EX, LOCK_UN and LOCK_NB constants.

        --
        Ilya Martynov (http://martynov.org/)

Re: unlink & rename in Win32
by IlyaM (Parson) on Dec 01, 2001 at 08:24 UTC
    AFAIK it is possible if these files are still opened. I'm not sure.

    --
    Ilya Martynov (http://martynov.org/)

      Unfortunately I'm relatively sure that that isn't the case. I'm the only one with acess to the system, no other programs touch the file... and I made a point of closing it before I tried to rename it and it still complains...


      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

Re: unlink & rename in Win32
by Flame (Deacon) on Dec 03, 2001 at 09:50 UTC
    So no one really knows why it won't rename (or delete?)


    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.12
    GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
    PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
    ------END GEEK CODE BLOCK------
    Translate

    "Weird things happen, get used to it."

    Flame ~ Lead Programmer: GMS