* Build a POSIX st_mode from SFTP Stats. * ssh2's Stats has .mode which already includes both file-type bits and * permission bits, but we also check the boolean helpers as a fallback.
(attrs: SFTPStats)
| 127 | * permission bits, but we also check the boolean helpers as a fallback. |
| 128 | */ |
| 129 | function buildStMode(attrs: SFTPStats): number { |
| 130 | const raw = attrs.mode; |
| 131 | // If mode already contains file-type bits, return as-is |
| 132 | if ((raw & S_IFMT) !== 0) return raw; |
| 133 | |
| 134 | // Derive file-type bits from the is* helpers |
| 135 | let typeBits = 0; |
| 136 | if (attrs.isDirectory()) typeBits = S_IFDIR; |
| 137 | else if (attrs.isFile()) typeBits = S_IFREG; |
| 138 | else if (attrs.isSymbolicLink()) typeBits = S_IFLNK; |
| 139 | else if (attrs.isSocket()) typeBits = S_IFSOCK; |
| 140 | else if (attrs.isCharacterDevice()) typeBits = S_IFCHR; |
| 141 | else if (attrs.isBlockDevice()) typeBits = S_IFBLK; |
| 142 | else if (attrs.isFIFO()) typeBits = S_IFIFO; |
| 143 | |
| 144 | return (raw & ~S_IFMT) | typeBits; |
| 145 | } |
| 146 | |
| 147 | function getSftpStatusCode(): typeof DEFAULT_SFTP_STATUS_CODE { |
| 148 | return { |