diff_unix.go 653 B

12345678910111213141516171819202122
  1. //go:build !windows
  2. // +build !windows
  3. package archive
  4. import "golang.org/x/sys/unix"
  5. // overrideUmask sets current process's file mode creation mask to newmask
  6. // and returns a function to restore it.
  7. //
  8. // WARNING for readers stumbling upon this code. Changing umask in a multi-
  9. // threaded environment isn't safe. Don't use this without understanding the
  10. // risks, and don't export this function for others to use (we shouldn't even
  11. // be using this ourself).
  12. //
  13. // FIXME(thaJeztah): we should get rid of these hacks if possible.
  14. func overrideUmask(newMask int) func() {
  15. oldMask := unix.Umask(newMask)
  16. return func() {
  17. unix.Umask(oldMask)
  18. }
  19. }