| 3909 | this.handle = handle; |
| 3910 | |
| 3911 | const tryAgain = (err) => { |
| 3912 | if (err) { |
| 3913 | // Try chmod() for sftp servers that may not support fchmod() for |
| 3914 | // whatever reason |
| 3915 | this.sftp.chmod(this.path, this.mode, (err_) => tryAgain()); |
| 3916 | return; |
| 3917 | } |
| 3918 | |
| 3919 | // SFTPv3 requires absolute offsets, no matter the open flag used |
| 3920 | if (this.flags[0] === 'a') { |
| 3921 | const tryStat = (err, st) => { |
| 3922 | if (err) { |
| 3923 | // Try stat() for sftp servers that may not support fstat() for |
| 3924 | // whatever reason |
| 3925 | this.sftp.stat(this.path, (err_, st_) => { |
| 3926 | if (err_) { |
| 3927 | this.destroy(); |
| 3928 | this.emit('error', err); |
| 3929 | return; |
| 3930 | } |
| 3931 | tryStat(null, st_); |
| 3932 | }); |
| 3933 | return; |
| 3934 | } |
| 3935 | |
| 3936 | this.pos = st.size; |
| 3937 | this.emit('open', handle); |
| 3938 | this.emit('ready'); |
| 3939 | }; |
| 3940 | |
| 3941 | this.sftp.fstat(handle, tryStat); |
| 3942 | return; |
| 3943 | } |
| 3944 | |
| 3945 | this.emit('open', handle); |
| 3946 | this.emit('ready'); |
| 3947 | }; |
| 3948 | |
| 3949 | this.sftp.fchmod(handle, this.mode, tryAgain); |
| 3950 | }); |