mode-fix.js 619 B

1234567891011121314151617181920212223
  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. // if dirs are readable, then they should be listable
  12. if (isDir) {
  13. if (mode & 0o400)
  14. mode |= 0o100
  15. if (mode & 0o40)
  16. mode |= 0o10
  17. if (mode & 0o4)
  18. mode |= 0o1
  19. }
  20. return mode
  21. }