On 08/30/2010 01:50 AM, Neil Van Dyke wrote:
> Has anyone already implemented Racket API for dealing with Unix file
> permissions/owner/group?

> * Procedure(s) to set a named file's permissions, owner, and/or group.
> 
> * Procedure to get the permissions, owner, and group of a named file.

Sure, I did that. I'll attach a quick demonstration.
#lang racket/base

(require (prefix-in perm: (planet synx/util:2/permissions))
         (prefix-in user: (planet synx/user:1))
         (prefix-in stat: (planet synx/stat:2))
         (prefix-in s: (planet synx/stat:2/lookup)))

(define (example)
  (define name "test.txt")
  (define info (user:info "synx"))
  (with-output-to-file
      name
    #:exists 'replace
    void)
  ; the following fails unless run as root or as whatever user you are
  (perm:chown name (user:user-uid info) (user:user-gid info))
  (perm:chmod name #o600)
  (let-values
      (((mode new-uid new-gid) (stat:stat name s:mode s:uid s:gid)))
    (write (list (number->string mode #o10) new-uid new-gid)))
  (newline)
  
  (with-output-to-file
      name
    #:exists 'append
    (λ ()
      (write '(secret stuff))
      (newline))))

(example)

Attachment: signature.asc
Description: OpenPGP digital signature

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Reply via email to