Unlinking files in Win32.

Unlinking files in Win32.

am 18.04.2006 00:54:12 von ismanager

Hi all,

First time posting here after a long time lurking. I have a problem that
though it seems it should be simple has proven elusive to me for a solution.

Up till a few weeks ago all my code had been running on Linux boxes. I've
never had a problem with any of them. Sadly our main web server suffered a
catastrophic failure and because we (the IT staff) have been told we would
have to move to a 100% Windows environment I moved all my code to a new(er)
Windows 2003 Server box. This server is running IIS 6 + ActiveState Perl
5.8.8 and PHP 4.4.2.

All the code transferred has worked perfectly or with minor tweaks (yeah
Perl portability!) except one. That one is our B2B program and is a critical
pieces of programming however it's old and uses files to keep track of data.
I planned on rewriting it but because of other situations I just have not
been able to spare the time. The situation is that program in question can
write and read its data files fine but it can not delete (unlink) them. I'm
not a Windows expert but we do have someone with more experience than I and
he's as stumped as I am. We've even gone so far as to give Full rights to
the directories in question to Guests, Everyone, Iusr_, .\Users, as well as
to Iwam_, nothing works. We even moved the directories out of the web site
tree and assigned the above full rights yet still it can't delete any files
that it creates.

Just to show I'm not trying to do something arcane, here is the (simple)
command I'm using:

unlink ($ticket_file_name) || &err_trap("Cannot delete
$ticket_file_name!\nMessage: $!\n");

With the above I get this:

Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
Permission denied

I'm at a loss so I ask for any suggestions. I think I've tried just about
everything but some how I feel that the answer is so obvious that I'm
totally missing it.

Thanks for any help in advance.

Paul Pettit
CTO and IS Manager
Consistent Computer Bargains Inc.

I've heard it said that the proof of lunacy is when you repeat the same
steps expecting different results. I say it's proof that you're a Microsoft
user. - comment by deshi777 on experts-exchange.com


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Unlinking files in Win32.

am 18.04.2006 01:41:34 von Jan Dubois

On Mon, 17 Apr 2006, Pettit, Paul wrote:
> Just to show I'm not trying to do something arcane, here is the (simple)
> command I'm using:
>
> unlink ($ticket_file_name) || &err_trap("Cannot delete
> $ticket_file_name!\nMessage: $!\n");
>
> With the above I get this:
>
> Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
> Permission denied

The 2 most common reasons for this are:

1) Some process still has an open handle for this file. You cannot delete
open files on Windows. You can rename them if you need to reuse the
the filename immediately, but you cannot delete them until all processes
have close all open handles for this file.

2) The file is marked read-only. You cannot unlink read-only files on
Windows. This is easy to fix though, you can just chmod(0666, $file)
before calling unlink($file).

Cheers,
-Jan



_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Unlinking files in Win32.

am 18.04.2006 01:41:59 von lynn

Pettit, Paul wrote:
> Hi all,
>
> First time posting here after a long time lurking. I have a problem that
> though it seems it should be simple has proven elusive to me for a solution.
>
> Up till a few weeks ago all my code had been running on Linux boxes. I've
> never had a problem with any of them. Sadly our main web server suffered a
> catastrophic failure and because we (the IT staff) have been told we would
> have to move to a 100% Windows environment I moved all my code to a new(er)
> Windows 2003 Server box. This server is running IIS 6 + ActiveState Perl
> 5.8.8 and PHP 4.4.2.
>
> All the code transferred has worked perfectly or with minor tweaks (yeah
> Perl portability!) except one. That one is our B2B program and is a critical
> pieces of programming however it's old and uses files to keep track of data.
> I planned on rewriting it but because of other situations I just have not
> been able to spare the time. The situation is that program in question can
> write and read its data files fine but it can not delete (unlink) them. I'm
> not a Windows expert but we do have someone with more experience than I and
> he's as stumped as I am. We've even gone so far as to give Full rights to
> the directories in question to Guests, Everyone, Iusr_, .\Users, as well as
> to Iwam_, nothing works. We even moved the directories out of the web site
> tree and assigned the above full rights yet still it can't delete any files
> that it creates.
>
> Just to show I'm not trying to do something arcane, here is the (simple)
> command I'm using:
>
> unlink ($ticket_file_name) || &err_trap("Cannot delete
> $ticket_file_name!\nMessage: $!\n");
>
> With the above I get this:
>
> Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
> Permission denied
>
> I'm at a loss so I ask for any suggestions. I think I've tried just about
> everything but some how I feel that the answer is so obvious that I'm
> totally missing it.
>
> Thanks for any help in advance.
>
> Paul Pettit

Opening thought - those files the script is reading and writing... Is
it _closing_ them when done?

- Lynn.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Unlinking files in Win32.

am 18.04.2006 02:22:18 von Petr Vileta

----- Original Message -----
From: "Pettit, Paul"
To:
Sent: Tuesday, April 18, 2006 12:54 AM
Subject: Unlinking files in Win32.


> Just to show I'm not trying to do something arcane, here is the (simple)
> command I'm using:
>
> unlink ($ticket_file_name) || &err_trap("Cannot delete
> $ticket_file_name!\nMessage: $!\n");
>
> With the above I get this:
>
> Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
> Permission denied
>
I don't know Windows 2003 Server and I don't use Perl 5.8.8, but I use WinXP
Pro and IIS and I'm abble to unlink any file what is created by IIS and perl
server-side script.
Maybe the file is used (opened) by another instance of perl script?
If you create the file look manualy to file properties. What is in the user
list and what privileges they have?

Petr Vileta, Czech republic
(My server reject all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Unlinking files in Win32.

am 18.04.2006 16:37:42 von Chris O

On Mon, 17 Apr 2006, Pettit, Paul wrote:
> Just to show I'm not trying to do something arcane, here is the
> (simple) command I'm using:
>
> unlink ($ticket_file_name) || &err_trap("Cannot delete
> $ticket_file_name!\nMessage: $!\n");
>
> With the above I get this:
>
> Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
> Permission denied

The 2 most common reasons for this are:

1) Some process still has an open handle for this file. You cannot delete
open files on Windows. You can rename them if you need to reuse the
the filename immediately, but you cannot delete them until all processes
have close all open handles for this file.

2) The file is marked read-only. You cannot unlink read-only files on
Windows. This is easy to fix though, you can just chmod(0666, $file)
before calling unlink($file).

Cheers,
-Jan

--------------------------------------

Also, unlink does not work reliably (in some cases at all) on windows unless
the complete file path is used.

- Chris


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Unlinking files in Win32.

am 18.04.2006 17:20:34 von Deane.Rothenmaier

This is a multipart message in MIME format.
--===============0336391916==
Content-Type: multipart/alternative;
boundary="=_alternative 00544B5286257154_="

This is a multipart message in MIME format.
--=_alternative 00544B5286257154_=
Content-Type: text/plain; charset="us-ascii"

Chris O:
> Also, unlink does not work reliably (in some cases at all) on windows
> unless the complete file path is used.

Call me old-fashioned, but I wouldn't think of doing *anything* to a file
using a filename that wasn't fully-pathed, **especially** deleting it.

Deane

--=_alternative 00544B5286257154_=
Content-Type: text/html; charset="us-ascii"



Chris O:

> Also, unlink does not work reliably (in some cases at all) on windows

> unless the complete file path is used.



Call me old-fashioned, but I wouldn't think of doing *anything* to a file using a filename that wasn't fully-pathed, **especially** deleting it.



Deane


--=_alternative 00544B5286257154_=--


--===============0336391916==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0336391916==--

RE: Unlinking files in Win32.

am 18.04.2006 17:42:35 von Jan Dubois

On Tue, 18 Apr 2006, Chris O wrote:
> Also, unlink does not work reliably (in some cases at all) on windows
> unless the complete file path is used.

I have not heard about this problem and kind of doubt that this is true.
It sounds more like user error in that the current directory was not set
to whatever the programmer was thinking it was.

Do you have any sample code that shows unlink() failing with a relative
filename?

Cheers,
-Jan


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Unlinking files in Win32.

am 18.04.2006 19:49:51 von Paul Pettit

> -----Original Message-----
>
> On Mon, 17 Apr 2006, Pettit, Paul wrote:
> > Just to show I'm not trying to do something arcane, here is the
> > (simple) command I'm using:
> >
> > unlink ($ticket_file_name) || &err_trap("Cannot delete
> > $ticket_file_name!\nMessage: $!\n");
> >
> > With the above I get this:
> >
> > Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
> > Permission denied
>
> The 2 most common reasons for this are:
>
> 1) Some process still has an open handle for this file. You
> cannot delete
> open files on Windows. You can rename them if you need to
> reuse the
> the filename immediately, but you cannot delete them until
> all processes
> have close all open handles for this file.
>
> 2) The file is marked read-only. You cannot unlink read-only files on
> Windows. This is easy to fix though, you can just
> chmod(0666, $file)
> before calling unlink($file).
>
> Cheers,
> -Jan
>
> --------------------------------------
>
> Also, unlink does not work reliably (in some cases at all) on
> windows unless
> the complete file path is used.
>
> - Chris
>
>

Thanks all.

File paths are complete paths (not relative or simple) so that wasn't the
issue. Indeed it was reason #1 that was the culprit.

I knew it had to be something simple I was missing. Seems the coding was a
bit sloppy and the Win box didn't like it.

Time to sit down and do that code revision I think. :P

Thanks again for pointing me in the right direction guys.

Paul Pettit
CTO and IS Manager
Consistent Computer Bargains Inc.

I've heard it said that the proof of lunacy is when you repeat the same
steps expecting different results. I say it's proof that you're a Microsoft
user. - comment by deshi777 on experts-exchange.com


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Unlinking files in Win32.

am 19.04.2006 01:56:55 von dbecoll

Deane.Rothenmaier@walgreens.com wrote:

>
> Chris O:
>> Also, unlink does not work reliably (in some cases at all) on windows
>> unless the complete file path is used.
>
> Call me old-fashioned, but I wouldn't think of doing *anything* to a
> file using a filename that wasn't fully-pathed, **especially** deleting it.

That's pretty paranoid - I do it all the time with no problems.

You just have to know where you are when you do it, know the file
perms and know who you're running as.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Unlinking files in Win32.

am 20.04.2006 03:14:34 von Paul Pettit

> -----Original Message-----
>
> On Mon, 17 Apr 2006, Pettit, Paul wrote:
> > Just to show I'm not trying to do something arcane, here is the
> > (simple) command I'm using:
> >
> > unlink ($ticket_file_name) || &err_trap("Cannot delete
> > $ticket_file_name!\nMessage: $!\n");
> >
> > With the above I get this:
> >
> > Program error: Cannot delete C:/wwwdata/tickets/570439140! Message:
> > Permission denied
>
> The 2 most common reasons for this are:
>
> 1) Some process still has an open handle for this file. You
> cannot delete
> open files on Windows. You can rename them if you need to
> reuse the
> the filename immediately, but you cannot delete them until
> all processes
> have close all open handles for this file.
>
> 2) The file is marked read-only. You cannot unlink read-only files on
> Windows. This is easy to fix though, you can just
> chmod(0666, $file)
> before calling unlink($file).
>
> Cheers,
> -Jan
>
> --------------------------------------
>
> Also, unlink does not work reliably (in some cases at all) on
> windows unless
> the complete file path is used.
>
> - Chris
>
>

Thanks all.

File paths are complete paths (not relative or simple) so that wasn't the
issue. Indeed it was reason #1 that was the culprit.

I knew it had to be something simple I was missing. Seems the coding was a
bit sloppy and the Win box didn't like it.

Time to sit down and do that code revision I think. :P

Thanks again for pointing me in the right direction guys.

Paul Pettit
CTO and IS Manager
Consistent Computer Bargains Inc.

I've heard it said that the proof of lunacy is when you repeat the same
steps expecting different results. I say it's proof that you're a Microsoft
user. - comment by deshi777 on experts-exchange.com


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs