#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)