Commit 11c7ff70 authored by Benjamin Chelli's avatar Benjamin Chelli

Add rmdir function in the API

parent 9e95c0eb
...@@ -94,7 +94,18 @@ Example: ...@@ -94,7 +94,18 @@ Example:
```javascript ```javascript
smb2Client.mkdir('path\\to\\the\\folder', function (err) { smb2Client.mkdir('path\\to\\the\\folder', function (err) {
if (err) throw err; if (err) throw err;
console.log('Folder created saved!'); console.log('Folder created!');
});
```
### smb2Client.rmdir ( path, callback )
Asynchronous rmdir(2). No arguments other than a possible exception are given to the completion callback.
Example:
```javascript
smb2Client.rmdir('path\\to\\the\\folder', function (err) {
if (err) throw err;
console.log('Folder deleted!');
}); });
``` ```
......
var SMB2Message = require('../message')
, message = require('../tools/message')
;
module.exports = message({
generate:function(connection, params){
var buffer = new Buffer(params.path, 'ucs2');
return new SMB2Message({
headers:{
'Command':'CREATE'
, 'SessionId':connection.SessionId
, 'TreeId':connection.TreeId
}
, request:{
'Buffer':buffer
, 'DesiredAccess':0x001701DF
, 'FileAttributes':0x00000000
, 'ShareAccess':0x00000007
, 'CreateDisposition':0x00000001
, 'CreateOptions':0x00200021
, 'NameOffset':0x0078
, 'CreateContextsOffset':0x007A+buffer.length
}
});
}
});
...@@ -432,17 +432,65 @@ proto.unlink = function(path, cb){ ...@@ -432,17 +432,65 @@ proto.unlink = function(path, cb){
} }
/*
* rmdir
* =====
*
* remove directory:
*
* - open the folder
*
* - remove the folder
*
* - close the folder
*
*/
proto.rmdir = function(path, cb){
var connection = this;
connect(connection, function(err){
cb = scheduleAutoClose(connection, cb);
if(err) cb(err);
else connection.exists(path, function(err, exists){
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(err){
cb && cb(null, files);
});
});
});
} else {
cb(new Error('Folder does not exists'));
}
});
});
}
/* /*
* mkdir * mkdir
* ===== * =====
* *
* create folder: * create folder:
* *
* - open the file * - create the folder
* *
* - remove the file * - close the folder
*
* - close the file
* *
*/ */
proto.mkdir = function(path, mode, cb){ proto.mkdir = function(path, mode, cb){
...@@ -464,7 +512,7 @@ proto.mkdir = function(path, mode, cb){ ...@@ -464,7 +512,7 @@ proto.mkdir = function(path, mode, cb){
else if(!exists){ else if(!exists){
// SMB2 open file // SMB2 open file
SMB2Request('create-folder', {path:path}, connection, function(err, file){ SMB2Request('create_folder', {path:path}, connection, function(err, file){
if(err) cb && cb(err); if(err) cb && cb(err);
// SMB2 query directory // SMB2 query directory
else SMB2Request('close', file, connection, function(err){ else SMB2Request('close', file, connection, function(err){
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
, "description":"SMB2 Client" , "description":"SMB2 Client"
, "homepage": "https://github.com/bchelli/node-smb2" , "homepage": "https://github.com/bchelli/node-smb2"
, "version":"0.2.2" , "version":"0.2.3"
, "engines": [ , "engines": [
"node" "node"
......
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