Ticket #731 (closed todo: fixed)

Opened 13 years ago

Last modified 11 years ago

can't tell if an OS file is executable from parrot

Reported by: coke Owned by: whiteknight
Priority: normal Milestone: 3.0
Component: core Version: master
Severity: medium Keywords: tcl blocker
Cc: Language: tcl
Patch status: Platform: all


Need this functionality for partcl's [file executable]  http://www.tcl.tk/man/tcl8.5/TclCmd/file.htm#M14

I don't see anything in docs/ that would indicate this is yet possible.

Change History

Changed 13 years ago by coke

  • lang set to tcl

Changed 13 years ago by whiteknight

can't you use the stat opcode?

Changed 13 years ago by coke

Not according to the documentation for the opcode, no.

However, if I follow the source code, I eventually get to stat_common(), which makes it look like "STAT_PLATFORM_MODE" might work.

This entry into the stat object that's returned doesn't seem to be documented anywhere, nor do the constants for stat seem to be pulled out somewhere where they can be used by name instead of magic number.

While a consistent interface would be better (something that unified the information available via stat and the File (or other) PMCs), if we stick with stat, we need to provide the same docs/PIR macro support as we do for other constants.

This should let get me something working with partcl, though. I'll post a link to the implementation later so folks can use it.

Changed 13 years ago by coke

Here's a sample that works for "o+x", but not "g+x" or "u+x" (for those, I need to know if I am the file owner, or if I'm in the group that is associated with the file.

.sub 'foo'
    $I0 = is_executable('parrot')
    say $I0
    $I0 = is_executable('MANIFEST')
    say $I0

.sub is_executable
    .param string filename

    # not exported from C to PIR
    .local int STAT_PLATFORM_MODE
    .local int UID
    UID = 9

    .local int mode
    mode = stat filename, STAT_PLATFORM_MODE

    .local int check_mode
    # is this executable by anyone?
    check_mode = band mode, 1
    if check_mode goto true

    # is this executable by the owner?
    check_mode = band mode, 64
    .local int file_uid
    file_uid = stat filename, UID
    .local int my_uid
    # XXX what's my effective UID?

    # is this executable by a group?
    check_mode = band mode, 8

    # XXX am I in that group?

    # If we got this far, it's not executable

    # Standard modes

Changed 13 years ago by jkeenan

  • component changed from none to core

Changed 11 years ago by whiteknight

  • owner set to whiteknight

Changed 11 years ago by whiteknight

  • status changed from new to assigned

I've created the get_user_id branch. In 32dbeca I added stub methods on the OS PMC to get the current user ID number, and to test r/w/x file permissions on a path.

Coke: Do these kinds of things look like they would satisfy what you need for this ticket?

Before this branch can be merged I need to figure out how to do these same things on Win32. Also, I need to write some basic documentation and add tests. If anybody can help with any of these tasks, it would make the work go much more quickly.

Changed 11 years ago by whiteknight

  • platform set to all
  • version set to master
  • milestone set to 3.0

I've assigned this as a GCI task to get tests written for this branch. I would like to see it tested and mergable by 3.0.

Changed 11 years ago by rfw

Test written and broken-ness fixed in my fork. See pull request:  https://github.com/parrot/parrot/pull/68

Changed 11 years ago by whiteknight

  • status changed from assigned to closed
  • resolution set to fixed

This has been merged with tests. Closing ticket.

Changed 11 years ago by coke

  • status changed from closed to reopened
  • resolution fixed deleted
On Tue, Jan 4, 2011 at 7:35 AM, Will Coleda <will@coleda.com> wrote:
> Since I don't see it anywhere in the ticket, this seems to be in the
> OS dynpmc in the "can_execute" method.
> Also appears to be unimplemented on windows (which makes me think we
> should leave it open.)
> --
> Will "Coke" Coleda

(resend. annoyingly, "reply-all" doesn't seem to include "tickets at
parrot.org" the last few messages I've replied to)

Will "Coke" Coleda

Changed 11 years ago by whiteknight

You're right Coke, I knew I was forgetting something. I'm going to focus on this today and try to get this issue resolved ASAP.

Changed 11 years ago by whiteknight

  • status changed from reopened to closed
  • resolution set to fixed

I fixed the windows case in ec9e3a0. Actually, my fix does simple extension matching over PATHEXT, which works for the simple test in t/dynpmc/os.t, but may not work in more advanced permissions setups, like on Windows server. Fixing this for those situations is no trivial task, but this commit works for the common case.

I'm closing this ticket. We can open a new ticket for the Win32 permissions problems later, if necessary.

Note: See TracTickets for help on using tickets.