MCPcopy Create free account
hub / github.com/mscdex/ssh2 / ext_openssh_lsetstat

Method ext_openssh_lsetstat

lib/protocol/SFTP.js:1502–1562  ·  view source on GitHub ↗
(path, attrs, cb)

Source from the content-addressed store, hash-verified

1500 );
1501 }
1502 ext_openssh_lsetstat(path, attrs, cb) {
1503 if (this.server)
1504 throw new Error('Client-only method called in server mode');
1505
1506 const ext = this._extensions['lsetstat@openssh.com'];
1507 if (ext !== '1')
1508 throw new Error('Server does not support this extended request');
1509
1510 let flags = 0;
1511 let attrsLen = 0;
1512
1513 if (typeof attrs === 'object' && attrs !== null) {
1514 attrs = attrsToBytes(attrs);
1515 flags = attrs.flags;
1516 attrsLen = attrs.nb;
1517 } else if (typeof attrs === 'function') {
1518 cb = attrs;
1519 }
1520
1521 /*
1522 uint32 id
1523 string "lsetstat@openssh.com"
1524 string path
1525 ATTRS attrs
1526 */
1527 const pathLen = Buffer.byteLength(path);
1528 let p = 9;
1529 const buf =
1530 Buffer.allocUnsafe(4 + 1 + 4 + 4 + 20 + 4 + pathLen + 4 + attrsLen);
1531
1532 writeUInt32BE(buf, buf.length - 4, 0);
1533 buf[4] = REQUEST.EXTENDED;
1534 const reqid = this._writeReqid = (this._writeReqid + 1) & MAX_REQID;
1535 writeUInt32BE(buf, reqid, 5);
1536
1537 writeUInt32BE(buf, 20, p);
1538 buf.utf8Write('lsetstat@openssh.com', p += 4, 20);
1539
1540 writeUInt32BE(buf, pathLen, p += 20);
1541 buf.utf8Write(path, p += 4, pathLen);
1542
1543 writeUInt32BE(buf, flags, p += pathLen);
1544 if (attrsLen) {
1545 p += 4;
1546
1547 if (attrsLen === ATTRS_BUF.length)
1548 buf.set(ATTRS_BUF, p);
1549 else
1550 bufferCopy(ATTRS_BUF, buf, 0, attrsLen, p);
1551
1552 p += attrsLen;
1553 }
1554
1555 this._requests[reqid] = { cb };
1556
1557 const isBuffered = sendOrBuffer(this, buf);
1558 if (this._debug) {
1559 const status = (isBuffered ? 'Buffered' : 'Sending');

Callers

nothing calls this directly

Calls 4

attrsToBytesFunction · 0.85
writeUInt32BEFunction · 0.85
bufferCopyFunction · 0.85
sendOrBufferFunction · 0.85

Tested by

no test coverage detected