Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Unlink help

Reply
Thread Tools

Unlink help

 
 
Dave Saville
Guest
Posts: n/a
 
      02-23-2013
I have a perl script that cleans up temporary directories at boot. If
a file in one of those directories is read only I get a "permission
denied" message from unlink. Note this is not a *nix or Windows
system. If OTOH I cd to said directory and issue "rm -f *" they go
without a murmur.

Can unlink be made to behave like "rm -f" or do I have to use the
command in backticks?

TIA
--
Regards
Dave Saville
 
Reply With Quote
 
 
 
 
Dave Saville
Guest
Posts: n/a
 
      02-23-2013
On Sat, 23 Feb 2013 09:49:38 UTC, "Dave Saville"
<> wrote:

> I have a perl script that cleans up temporary directories at boot. If
> a file in one of those directories is read only I get a "permission
> denied" message from unlink. Note this is not a *nix or Windows
> system. If OTOH I cd to said directory and issue "rm -f *" they go
> without a murmur.
>
> Can unlink be made to behave like "rm -f" or do I have to use the
> command in backticks?
>


My mistake - it is not files that are read only. I can see no
difference between files it will delete and those it won't It usually
happens when it is trying to delete an unloaded tarball - some of the
files give "permission denied".

--
Regards
Dave Saville
 
Reply With Quote
 
 
 
 
Dave Saville
Guest
Posts: n/a
 
      02-23-2013
On Sat, 23 Feb 2013 11:57:09 UTC, Ben Morrow <> wrote:

Hi Ben

>
> Quoth "Dave Saville" <>:
> > On Sat, 23 Feb 2013 09:49:38 UTC, "Dave Saville"
> > <> wrote:
> >
> > > I have a perl script that cleans up temporary directories at boot. If
> > > a file in one of those directories is read only I get a "permission
> > > denied" message from unlink. Note this is not a *nix or Windows
> > > system.

>
> What sort of system is it?


OS/2

>
> > > If OTOH I cd to said directory and issue "rm -f *" they go
> > > without a murmur.
> > >
> > > Can unlink be made to behave like "rm -f" or do I have to use the
> > > command in backticks?


Thanks for the tip to use system rather than backticks. But I don't
think permissions has anything to do with it. For instance:

[T:\tmp\openjdk6_b27_jre_os2_ga5-20130217]ls -l
total 192
-rw-rw-rw- 1 root 0 1530 Feb 17 02:30 ASSEMBLY_EXCEPTION
drwxrwxrwx 1 root 0 0 Feb 23 12:11 bin
-rw-rw-rw- 1 root 0 7526 Feb 17 00:18 CHANGES.OS2
drwxrwxrwx 1 root 0 0 Feb 23 12:11 lib
-rw-rw-rw- 1 root 0 19610 Feb 17 02:30 LICENSE
-rw-rw-rw- 1 root 0 13299 Feb 17 00:41 README.OS2
-rw-rw-rw- 1 root 0 129126 Feb 17 02:30 THIRD_PARTY_README

I run my script and afterwards:

[T:\]ls -lR /tmp/openjdk6_b27_jre_os2_ga5-20130217/
/tmp/openjdk6_b27_jre_os2_ga5-20130217/:
total 32
-rw-rw-rw- 1 root 0 1530 Feb 17 02:30 ASSEMBLY_EXCEPTION
drwxrwxrwx 1 root 0 0 Feb 23 10:39 lib
-rw-rw-rw- 1 root 0 19610 Feb 17 02:30 LICENSE

The script threw permission denied on those two files and some in lib
which is why lib is still there of course - not empty.

Upon reflection I guess it must be an OS thing - I really just posted
here in case there was an option to unlink I did not know about.
--
Regards
Dave Saville
 
Reply With Quote
 
Dave Saville
Guest
Posts: n/a
 
      02-23-2013
On Sat, 23 Feb 2013 12:31:45 UTC, "Dave Saville"
<> wrote:

<snip>

> Upon reflection I guess it must be an OS thing - I really just posted
> here in case there was an option to unlink I did not know about.


Well sort of - For the last few weeks I have been using a linux system
and once again got used to believing the permissions displayed by ls.
It would seem that I was right the first time and it is read only
files - despite what ls was telling me. OS/2 sort of supports file
perms although it does not do much with them. ls was saying the file
was rw whilst attrib said read only. The odd thing is if you chmod the
file with any old mix of perms you like ls *and* attrib reflect them.
Ho hum. Quick fix as Ben suggested is to chmod the file 777 before
trying to delete it.

--
Regards
Dave Saville
 
Reply With Quote
 
greymaus
Guest
Posts: n/a
 
      02-23-2013
On 2013-02-23, Ben Morrow <> wrote:
>
> Quoth "Dave Saville" <>:
>> On Sat, 23 Feb 2013 09:49:38 UTC, "Dave Saville"
>> <> wrote:
>>
>> > I have a perl script that cleans up temporary directories at boot. If
>> > a file in one of those directories is read only I get a "permission
>> > denied" message from unlink. Note this is not a *nix or Windows
>> > system.

>
> What sort of system is it?


My own thought, as most/all ssystems now are *unix or windows.

>
>> > If OTOH I cd to said directory and issue "rm -f *" they go
>> > without a murmur.
>> >
>> > Can unlink be made to behave like "rm -f" or do I have to use the
>> > command in backticks?

>
> Unlink alone cannot be made to do anything other than call unlink(2) (or
> your local equivalent). If your system uses Unix-like permissions, or if
> perl emulates them sufficiently, you can change the relevant permissions
> with chmod before trying the unlink. You can also use
> File:ath::rmtree, which will do this for you.
>
> If you do decide to run rm(1), do it with system rather than backticks.
>
>> My mistake - it is not files that are read only. I can see no
>> difference between files it will delete and those it won't It usually
>> happens when it is trying to delete an unloaded tarball - some of the
>> files give "permission denied".

>
> Under Unix you need write permission to a directory to delete files in
> it. If that's not the case on your system you will need to find out what
> is making the difference.
>
> Ben
>



--
maus
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      02-23-2013
On 2013-02-23 12:31, Dave Saville <> wrote:
> On Sat, 23 Feb 2013 11:57:09 UTC, Ben Morrow <> wrote:
>> Quoth "Dave Saville" <>:
>> > On Sat, 23 Feb 2013 09:49:38 UTC, "Dave Saville"
>> > <> wrote:
>> > > I have a perl script that cleans up temporary directories at boot. If
>> > > a file in one of those directories is read only I get a "permission
>> > > denied" message from unlink. Note this is not a *nix or Windows
>> > > system.

>>
>> What sort of system is it?

>
> OS/2

[...]
> [T:\tmp\openjdk6_b27_jre_os2_ga5-20130217]ls -l
> total 192
> -rw-rw-rw- 1 root 0 1530 Feb 17 02:30 ASSEMBLY_EXCEPTION


Does OS/2 come with an "ls" command or is this a from a third party? If
it's not a native command then I would assume that it doesn't display
the real permissions as implementend by the OS, but some unix-like
approximation.

hp


--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR | Man feilt solange an seinen Text um, bis
| | | | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel
 
Reply With Quote
 
Dave Saville
Guest
Posts: n/a
 
      02-24-2013
On Sat, 23 Feb 2013 21:29:30 UTC, "Peter J. Holzer"
<hjp-> wrote:

> On 2013-02-23 12:31, Dave Saville <> wrote:
> > On Sat, 23 Feb 2013 11:57:09 UTC, Ben Morrow <> wrote:
> >> Quoth "Dave Saville" <>:
> >> > On Sat, 23 Feb 2013 09:49:38 UTC, "Dave Saville"
> >> > <> wrote:
> >> > > I have a perl script that cleans up temporary directories at boot. If
> >> > > a file in one of those directories is read only I get a "permission
> >> > > denied" message from unlink. Note this is not a *nix or Windows
> >> > > system.
> >>
> >> What sort of system is it?

> >
> > OS/2

> [...]
> > [T:\tmp\openjdk6_b27_jre_os2_ga5-20130217]ls -l
> > total 192
> > -rw-rw-rw- 1 root 0 1530 Feb 17 02:30 ASSEMBLY_EXCEPTION

>
> Does OS/2 come with an "ls" command or is this a from a third party? If
> it's not a native command then I would assume that it doesn't display
> the real permissions as implementend by the OS, but some unix-like
> approximation.


No it's a port. What I have discovered is that it stores the *nix
perms in the file's Extended Attributes. If there are none then it
displays -rw-rw-rw for files and drwxrwxrwx for directories. It knows
nothing about DOSish attributes of Archive, System, Hidden & Read
only. However, if one uses the, also ported, chmod then the EA's are
changed for persistance *and* if the bit in question is "Read only" it
also updates the OS attribute. Unfortunately it does not work the
other way around. ie if one uses attrib +R foo it does not see it.

This particular problem was un-archiving a zip with some files read
only. The OS attribute was set but not the EA's.
--
Regards
Dave Saville
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: os.unlink on Windows Thomas Jollans Python 5 08-09-2010 08:08 AM
How can I unlink/delete an open file in Windows? Coffee Pot C Programming 12 10-19-2008 11:04 PM
ios::trunc vs unlink aryan C++ 3 06-17-2008 07:15 AM
perlcc error - 'Can't unlink error file...' Paul Urbanus Perl 0 04-07-2006 01:34 PM
os.unlink() AND win32api.DeleteFile() rbt Python 4 01-24-2006 01:17 PM



Advertisments