Commit 4b8f5754 authored by Julien Fontanet's avatar Julien Fontanet

fix(rmdir): dont test existence

Test pre-condition can leads to race-conditions.
Also current code was hiding SMB error.
parent e3fd38fa
......@@ -18,37 +18,27 @@ var SMB2Forge = require('../tools/smb2-forge'),
module.exports = function rmdir(path, cb) {
var connection = this;
connection.exists(path, function(err, exists) {
// SMB2 open file
SMB2Request('open_folder', { path: path }, connection, function(err, file) {
if (err) cb && cb(err);
else if (exists) {
// SMB2 open file
SMB2Request('open_folder', { path: path }, 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) {
if (err) cb && cb(err);
// SMB2 close directory
else
SMB2Request('close', file, connection, function() {
cb && cb(null, files);
});
}
);
});
} else {
cb(new Error('Folder does not exists'));
}
// SMB2 query directory
else
SMB2Request(
'set_info',
{
FileId: file.FileId,
FileInfoClass: 'FileDispositionInformation',
Buffer: new bigint(1, 1).toBuffer(),
},
connection,
function(err, files) {
if (err) cb && cb(err);
// SMB2 close directory
else
SMB2Request('close', file, connection, function() {
cb && cb(null, files);
});
}
);
});
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment