feat(fs/smb): implement rmdir

This commit is contained in:
Julien Fontanet 2018-12-03 13:11:31 +01:00
parent ddb1a8ff51
commit d7ac1b9659
3 changed files with 26 additions and 18 deletions

View File

@ -20,7 +20,7 @@
"node": ">=6"
},
"dependencies": {
"@marsaud/smb2": "^0.9.0",
"@marsaud/smb2": "^0.10.0",
"@xen-orchestra/async-map": "^0.0.0",
"execa": "^1.0.0",
"fs-extra": "^7.0.0",

View File

@ -17,8 +17,10 @@ class ErrorWrapper extends Error {
const normalizeError = (error, shouldBeDirectory) => {
const { code } = error
return code === 'STATUS_OBJECT_NAME_NOT_FOUND' ||
code === 'STATUS_OBJECT_PATH_NOT_FOUND'
return code === 'STATUS_DIRECTORY_NOT_EMPTY'
? new ErrorWrapper(error, 'ENOTEMPTY')
: code === 'STATUS_OBJECT_NAME_NOT_FOUND' ||
code === 'STATUS_OBJECT_PATH_NOT_FOUND'
? new ErrorWrapper(error, 'ENOENT')
: code === 'STATUS_NOT_SUPPORTED' || code === 'STATUS_INVALID_PARAMETER'
? new ErrorWrapper(error, shouldBeDirectory ? 'ENOTDIR' : 'EISDIR')
@ -126,6 +128,17 @@ export default class SmbHandler extends RemoteHandlerAbstract {
}
}
async _rmdir(dir) {
const client = this._getClient()
try {
await client.rmdir(this._getFilePath(dir))
} catch (error) {
throw normalizeError(error, true)
} finally {
client.disconnect()
}
}
async _list(dir = '.') {
const client = this._getClient()
try {

View File

@ -799,13 +799,13 @@
normalize-path "^2.0.1"
through2 "^2.0.3"
"@marsaud/smb2@^0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@marsaud/smb2/-/smb2-0.9.0.tgz#e63df305ce73a7672492100c29b6ebe203bf3550"
integrity sha512-5bnasEADFjB4bDoZyghP0ooMscLGEf0A6PkNy//K5xpv5cVIUKavTTi6a92ehlyJInZtsHjeTTk0sOu8NlhFxQ==
"@marsaud/smb2@^0.10.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/@marsaud/smb2/-/smb2-0.10.0.tgz#7e356b0a4735d1f1b924c2977a4c4e59508c9a89"
integrity sha512-lzUulrW2xZ72zizSSu8/suUvntfvTVLr5ixIgB/5lC1pJFYPuE/tPwa3rw6xl3nRQhmVXMSToDVPnOjT7gJGCg==
dependencies:
babel-runtime "^5.8.34"
bluebird "^2.10.2"
bluebird "^3.5.3"
ntlm "~0.1.1"
"@mrmlnc/readdir-enhanced@^2.2.1":
@ -1127,10 +1127,10 @@ anymatch@^2.0.0:
micromatch "^3.1.4"
normalize-path "^2.1.1"
app-conf@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/app-conf/-/app-conf-0.6.0.tgz#89160ba0369bd6a864c90a55d4a25f422e9ee595"
integrity sha512-FknU1++wj1E5tSV5FkcVz/8RTvZD79zLSuIefoP2U3WLGx3bWVUEBPx3bzTDNBMuPpcWNeMMQByKYheML/Y+lg==
app-conf@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/app-conf/-/app-conf-0.6.1.tgz#4361b07d9ec94c020b60458ca4271dbcac2d74bd"
integrity sha512-Tin1pF9ijn1OMkVCC9qFFAH5GvQxa+lDDoCA4z9LhzbbSHFbT+L6i/1YW7+RdV+EnwHuYTt8uvtf7rsrqeY+eg==
dependencies:
glob "^7.1.3"
lodash "^4.17.11"
@ -2552,12 +2552,7 @@ blocked@^1.2.1:
resolved "https://registry.yarnpkg.com/blocked/-/blocked-1.2.1.tgz#e22efe767863c65ab8197f6252929104e1ec9ce2"
integrity sha1-4i7+dnhjxlq4GX9iUpKRBOHsnOI=
bluebird@^2.10.2:
version "2.11.0"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1"
integrity sha1-U0uQM8AiyVecVro7Plpcqvu2UOE=
bluebird@^3.5.1:
bluebird@^3.5.1, bluebird@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==