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'), ...@@ -18,37 +18,27 @@ var SMB2Forge = require('../tools/smb2-forge'),
module.exports = function rmdir(path, cb) { module.exports = function rmdir(path, cb) {
var connection = this; 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); if (err) cb && cb(err);
else if (exists) { // SMB2 query directory
// SMB2 open file else
SMB2Request('open_folder', { path: path }, connection, function( SMB2Request(
err, 'set_info',
file {
) { FileId: file.FileId,
if (err) cb && cb(err); FileInfoClass: 'FileDispositionInformation',
// SMB2 query directory Buffer: new bigint(1, 1).toBuffer(),
else },
SMB2Request( connection,
'set_info', function(err, files) {
{ if (err) cb && cb(err);
FileId: file.FileId, // SMB2 close directory
FileInfoClass: 'FileDispositionInformation', else
Buffer: new bigint(1, 1).toBuffer(), SMB2Request('close', file, connection, function() {
}, cb && cb(null, files);
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'));
}
}); });
}; };
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