From 80b74f0a844eb60a8e69db81670f4e3440b06da0 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sun, 11 Apr 2021 12:40:42 +0200 Subject: [PATCH] chore: format with Prettier --- lib/api/createReadStream.js | 2 +- lib/api/createWriteStream.js | 2 +- lib/api/rename.js | 6 ++++- lib/api/unlink.js | 45 +++++++++++++++++++---------------- lib/tools/smb2-connection.js | 46 ++++++++++++++++-------------------- 5 files changed, 52 insertions(+), 49 deletions(-) diff --git a/lib/api/createReadStream.js b/lib/api/createReadStream.js index b3ada98..1fb46ac 100644 --- a/lib/api/createReadStream.js +++ b/lib/api/createReadStream.js @@ -16,7 +16,7 @@ module.exports = function createReadStream(path, options, cb) { var fd = options.fd; var isFd = fd != null; - var shouldClose = !isFd || (options.autoClose == null || options.autoClose); + var shouldClose = !isFd || options.autoClose == null || options.autoClose; function onOpen(err, file) { if (err != null) { diff --git a/lib/api/createWriteStream.js b/lib/api/createWriteStream.js index af793e4..ecef957 100644 --- a/lib/api/createWriteStream.js +++ b/lib/api/createWriteStream.js @@ -15,7 +15,7 @@ module.exports = function createWriteStream(path, options, cb) { var fd = options.fd; var isFd = fd != null; - var shouldClose = !isFd || (options.autoClose == null || options.autoClose); + var shouldClose = !isFd || options.autoClose == null || options.autoClose; function onCreate(err, file) { if (err != null) { diff --git a/lib/api/rename.js b/lib/api/rename.js index ba37373..10f2823 100644 --- a/lib/api/rename.js +++ b/lib/api/rename.js @@ -31,7 +31,11 @@ module.exports = function rename(oldPath, newPath, options, cb) { if (err) SMB2Request( 'create', - { path: oldPath, createDisposition: constants.FILE_OPEN, shareAccess: constants.FILE_SHARE_DELETE }, + { + path: oldPath, + createDisposition: constants.FILE_OPEN, + shareAccess: constants.FILE_SHARE_DELETE, + }, connection, function(err, file) { if (err) cb && cb(err); diff --git a/lib/api/unlink.js b/lib/api/unlink.js index efb54d1..965e7cb 100644 --- a/lib/api/unlink.js +++ b/lib/api/unlink.js @@ -19,24 +19,29 @@ module.exports = function unlink(path, cb) { var connection = this; // SMB2 open file - SMB2Request('create', { path: path, shareAccess: constants.FILE_SHARE_DELETE }, connection, function(err, file) { - if (err) cb && cb(err); - // SMB2 query directory - else - SMB2Request( - 'set_info', - { - FileId: file.FileId, - FileInfoClass: 'FileDispositionInformation', - Buffer: new BigInt(1, 1).toBuffer(), - }, - connection, - function(err, files) { - SMB2Request('close', file, connection, function() { - if (err) cb && cb(err); - else cb && cb(null, files); - }); - } - ); - }); + SMB2Request( + 'create', + { path: path, shareAccess: constants.FILE_SHARE_DELETE }, + connection, + function(err, file) { + if (err) cb && cb(err); + // SMB2 query directory + else + SMB2Request( + 'set_info', + { + FileId: file.FileId, + FileInfoClass: 'FileDispositionInformation', + Buffer: new BigInt(1, 1).toBuffer(), + }, + connection, + function(err, files) { + SMB2Request('close', file, connection, function() { + if (err) cb && cb(err); + else cb && cb(null, files); + }); + } + ); + } + ); }; diff --git a/lib/tools/smb2-connection.js b/lib/tools/smb2-connection.js index 0420b10..e10743f 100644 --- a/lib/tools/smb2-connection.js +++ b/lib/tools/smb2-connection.js @@ -28,30 +28,27 @@ SMB2Connection.requireConnect = function(method) { return function() { var connection = this; var args = Array.prototype.slice.call(arguments); - connect( - connection, - function(err) { - // process the cb - var cb = args.pop(); - if (typeof cb !== 'function') { - args.push(cb); - cb = function(err) { - if (err) { - if (!(err instanceof Error)) { - err = new Error(String(err)); - } - throw err; - } - }; - } - cb = scheduleAutoClose(connection, cb); + connect(connection, function(err) { + // process the cb + var cb = args.pop(); + if (typeof cb !== 'function') { args.push(cb); - - // manage the connection error - if (err) cb(err); - else method.apply(connection, args); + cb = function(err) { + if (err) { + if (!(err instanceof Error)) { + err = new Error(String(err)); + } + throw err; + } + }; } - ); + cb = scheduleAutoClose(connection, cb); + args.push(cb); + + // manage the connection error + if (err) cb(err); + else method.apply(connection, args); + }); }; }; @@ -97,10 +94,7 @@ function connect(connection, cb) { connection.SessionId = Math.floor(Math.random() * 256) & 0xff; // open TCP socket - connection.socket.connect( - connection.port, - connection.ip - ); + connection.socket.connect(connection.port, connection.ip); // SMB2 negotiate connection SMB2Request('negotiate', {}, connection, function(err) {