mode-fix.js 624 B

123456789101112131415161718192021222324
  1. 'use strict'
  2. module.exports = (mode, isDir, portable) => {
  3. mode &= 0o7777
  4. // in portable mode, use the minimum reasonable umask
  5. // if this system creates files with 0o664 by default
  6. // (as some linux distros do), then we'll write the
  7. // archive with 0o644 instead. Also, don't ever create
  8. // a file that is not readable/writable by the owner.
  9. if (portable) {
  10. mode = (mode | 0o600) &~0o22
  11. }
  12. // if dirs are readable, then they should be listable
  13. if (isDir) {
  14. if (mode & 0o400)
  15. mode |= 0o100
  16. if (mode & 0o40)
  17. mode |= 0o10
  18. if (mode & 0o4)
  19. mode |= 0o1
  20. }
  21. return mode
  22. }