Commit a2a550a9 authored by Julien Fontanet's avatar Julien Fontanet

feat: remove ensureDir

The current implementation was broken (it did not always close dir handlers).

Removing this method also permit us to remove the following dependencies:
- Babel 5 (very old and unmaintained)
- Bluebird
parent e4f5e460
{
"comments": false,
"compact": true,
"optional": [
// Experimental features.
// "minification.constantFolding",
// "minification.deadCodeElimination",
"es7.asyncFunctions",
"es7.decorators",
"es7.exportExtensions",
"es7.functionBind",
"runtime"
]
}
......@@ -78,19 +78,6 @@ smb2Client.disconnect();
### High level methods
> `smb2Client.ensureDir ( path, callback )`
Ensures that the directory exists. If the directory structure does not exist, it is created.
Example:
```javascript
smb2Client.ensureDir('path\\to\\directory', function(err) {
if (err) throw err;
console.log('directory structure has been created');
});
```
> `smb2Client.exists ( path, callback )`
Test whether or not the given path exists by checking with the file system.
......
import { request } from '../tools/smb2-forge';
import Bluebird from 'bluebird';
const requestAsync = Bluebird.promisify(request);
const ensureOneDir = async function(path, connection) {
try {
const fileOrDir = await requestAsync('open', { path }, connection);
if (fileOrDir.FileAttributes.readIntBE(0, 1) === 0x00000010) {
// See http://download.microsoft.com/DOWNLOAD/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/[MS-FSCC].pdf Section 2.6
await requestAsync('close', fileOrDir, connection);
} else {
throw new Error(`${path} exists but is not a directory`);
}
} catch (err) {
if (err.code === 'STATUS_OBJECT_NAME_NOT_FOUND') {
try {
await requestAsync('create_folder', { path }, connection);
} catch (err) {
if (err.code !== 'STATUS_OBJECT_NAME_COLLISION') {
throw err;
}
}
} else {
throw err;
}
}
};
export default async function(path, cb) {
const structure = path.split('\\');
const base = [];
try {
while (structure.length) {
base.push(structure.shift());
const basePath = base.join('\\');
if (!basePath.length) {
continue;
}
await ensureOneDir(basePath, this);
}
cb(null);
} catch (error) {
cb(error);
}
}
......@@ -115,9 +115,6 @@ proto.mkdir = autoPromise(
SMB2Connection.requireConnect(require('./api/mkdir'))
);
proto.ensureDir = autoPromise(
SMB2Connection.requireConnect(require('./api/ensureDir'))
);
proto.getSize = autoPromise(
SMB2Connection.requireConnect(require('./api/getSize'))
);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -20,8 +20,6 @@
"url": "https://github.com/marsaud/node-smb2"
},
"dependencies": {
"babel-runtime": "^5.8.34",
"bluebird": "^3.5.3",
"ntlm": "~0.1.1"
},
"keywords": [
......@@ -33,12 +31,9 @@
"Samba"
],
"scripts": {
"build": "./node_modules/.bin/babel --source-maps --out-dir=lib/api/ lib/api/src",
"prepublish": "npm run build",
"test": "eslint ./lib"
},
"devDependencies": {
"babel": "^5.8.34",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-standard": "^12.0.0",
......
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