Skip to content

Commit

Permalink
chore: format with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Apr 11, 2021
1 parent 7f5124b commit 80b74f0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/api/createReadStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/api/createWriteStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion lib/api/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 25 additions & 20 deletions lib/api/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
);
}
);
};
46 changes: 20 additions & 26 deletions lib/tools/smb2-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
};

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 80b74f0

Please sign in to comment.