code.gitea.io/gitea@v1.19.3/modules/util/file_unix.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 //go:build !windows 5 6 package util 7 8 import ( 9 "os" 10 11 "golang.org/x/sys/unix" 12 ) 13 14 var defaultUmask int 15 16 func init() { 17 // at the moment, the umask could only be gotten by calling unix.Umask(newUmask) 18 // use 0o077 as temp new umask to reduce the risks if this umask is used anywhere else before the correct umask is recovered 19 tempUmask := 0o077 20 defaultUmask = unix.Umask(tempUmask) 21 unix.Umask(defaultUmask) 22 } 23 24 func ApplyUmask(f string, newMode os.FileMode) error { 25 mod := newMode & ^os.FileMode(defaultUmask) 26 return os.Chmod(f, mod) 27 }