You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

file_unix.go 628B

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