Posted to tcl by sebres at Tue Sep 15 21:28:37 GMT 2026view pretty
testConstraint readonlyAttr 0
if {[testConstraint unix]} {
set f [makeFile "whatever" probe]
catch {
if {[catch { file attributes $f -readonly 1; file attributes $f -readonly 0 }]} {
switch -- $::tcl_platform(os) {
"FreeBSD" - "Darwin" {
# FreeBSD and macOS (BSD-based)
# Fixes FreeBSD ZFS bug where unsetting masks failure
exec chflags uchg $f
exec chflags nouchg $f
}
"Linux" {
# Linux (requires root/CAP_LINUX_IMMUTABLE to succeed)
exec chattr +i $f
exec chattr -i $f
}
"SunOS" {
# Solaris / Illumos / OpenIndiana (ZFS native attributes)
exec chmod +N readonly $f
exec chmod -N readonly $f
}
default {
# Fallback for NetBSD, OpenBSD, AIX, HP-UX, etc.
file attributes $f -readonly
}
}
}
testConstraint readonlyAttr 1
}
removeFile probe
}