Posted to tcl by sebres at Tue Sep 15 21:28:37 GMT 2026view raw

  1. testConstraint readonlyAttr 0
  2. if {[testConstraint unix]} {
  3. set f [makeFile "whatever" probe]
  4. catch {
  5. if {[catch { file attributes $f -readonly 1; file attributes $f -readonly 0 }]} {
  6. switch -- $::tcl_platform(os) {
  7. "FreeBSD" - "Darwin" {
  8. # FreeBSD and macOS (BSD-based)
  9. # Fixes FreeBSD ZFS bug where unsetting masks failure
  10. exec chflags uchg $f
  11. exec chflags nouchg $f
  12. }
  13. "Linux" {
  14. # Linux (requires root/CAP_LINUX_IMMUTABLE to succeed)
  15. exec chattr +i $f
  16. exec chattr -i $f
  17. }
  18. "SunOS" {
  19. # Solaris / Illumos / OpenIndiana (ZFS native attributes)
  20. exec chmod +N readonly $f
  21. exec chmod -N readonly $f
  22. }
  23. default {
  24. # Fallback for NetBSD, OpenBSD, AIX, HP-UX, etc.
  25. file attributes $f -readonly
  26. }
  27. }
  28. }
  29. testConstraint readonlyAttr 1
  30. }
  31. removeFile probe
  32. }
  33.  

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week