Unlink help

Discussion in 'Perl Misc' started by Dave Saville, Feb 23, 2013.

  1. Dave Saville

    Dave Saville Guest

    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
     
    Dave Saville, Feb 23, 2013
    #1
    1. Advertising

  2. Dave Saville

    Dave Saville Guest

    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
     
    Dave Saville, Feb 23, 2013
    #2
    1. Advertising

  3. Dave Saville

    Dave Saville Guest

    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
     
    Dave Saville, Feb 23, 2013
    #3
  4. Dave Saville

    Dave Saville Guest

    Re: Unlink help - Solved - sort of

    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
     
    Dave Saville, Feb 23, 2013
    #4
  5. Dave Saville

    greymaus Guest

    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::path::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
     
    greymaus, Feb 23, 2013
    #5
  6. 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
     
    Peter J. Holzer, Feb 23, 2013
    #6
  7. Dave Saville

    Dave Saville Guest

    On Sat, 23 Feb 2013 21:29:30 UTC, "Peter J. Holzer"
    <> 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
     
    Dave Saville, Feb 24, 2013
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Urbanus
    Replies:
    0
    Views:
    2,272
    Paul Urbanus
    Apr 7, 2006
  2. rbt
    Replies:
    4
    Views:
    2,231
  3. aryan

    ios::trunc vs unlink

    aryan, Jun 16, 2008, in forum: C++
    Replies:
    3
    Views:
    796
    James Kanze
    Jun 17, 2008
  4. Coffee Pot

    How can I unlink/delete an open file in Windows?

    Coffee Pot, Oct 18, 2008, in forum: C Programming
    Replies:
    12
    Views:
    726
    CBFalconer
    Oct 20, 2008
  5. Thomas Jollans

    Re: os.unlink on Windows

    Thomas Jollans, Aug 7, 2010, in forum: Python
    Replies:
    5
    Views:
    869
    Lawrence D'Oliveiro
    Aug 9, 2010
Loading...

Share This Page