chore(package): update xo-remote-parser to version 0.3.0 (#333)

This commit is contained in:
Fabrice Marsaud 2016-06-08 17:26:08 +02:00 committed by Julien Fontanet
parent 6dde1ade01
commit 143e53c43f
4 changed files with 26 additions and 16 deletions

View File

@ -129,7 +129,7 @@
"xml2js": "~0.4.6",
"xo-acl-resolver": "0.2.0",
"xo-collection": "^0.4.0",
"xo-remote-parser": "^0.2.1"
"xo-remote-parser": "^0.3"
},
"devDependencies": {
"babel-eslint": "^6.0.4",

View File

@ -15,7 +15,7 @@ import {
export default class RemoteHandlerAbstract {
constructor (remote) {
this._remote = parse({...remote})
this._remote = {...remote, ...parse(remote.url)}
if (this._remote.type !== this.type) {
throw new Error('Incorrect remote type')
}

View File

@ -12,16 +12,21 @@ import {
export default class LocalHandler extends RemoteHandlerAbstract {
get type () {
return 'local'
return 'file'
}
_getRealPath () {
return this._remote.path
}
_getFilePath (file) {
const parts = [this._remote.path]
const realPath = this._getRealPath()
const parts = [realPath]
if (file) {
parts.push(file)
}
const path = resolve.apply(null, parts)
if (!startsWith(path, this._remote.path)) {
if (!startsWith(path, realPath)) {
throw new Error('Remote path is unavailable')
}
return path
@ -30,8 +35,9 @@ export default class LocalHandler extends RemoteHandlerAbstract {
async _sync () {
if (this._remote.enabled) {
try {
await fs.ensureDir(this._remote.path)
await fs.access(this._remote.path, fs.R_OK | fs.W_OK)
const path = this._getRealPath()
await fs.ensureDir(path)
await fs.access(path, fs.R_OK | fs.W_OK)
} catch (exc) {
this._remote.enabled = false
this._remote.error = exc.message
@ -47,7 +53,7 @@ export default class LocalHandler extends RemoteHandlerAbstract {
async _outputFile (file, data, options) {
const path = this._getFilePath(file)
await fs.ensureDir(dirname(path))
await fs.writeFile(this._getFilePath(file), data, options)
await fs.writeFile(path, data, options)
}
async _readFile (file, options) {

View File

@ -11,6 +11,10 @@ export default class NfsHandler extends LocalHandler {
return 'nfs'
}
_getRealPath () {
return `/tmp/xo-server/mounts/${this._remote.id}`
}
async _loadRealMounts () {
let stdout
const mounted = {}
@ -37,27 +41,27 @@ export default class NfsHandler extends LocalHandler {
return mounted
}
_matchesRealMount (remote) {
return remote.path in this._realMounts
_matchesRealMount () {
return this._getRealPath() in this._realMounts
}
async _mount (remote) {
await fs.ensureDir(remote.path)
return execa('mount', ['-t', 'nfs', '-o', 'vers=3', `${remote.host}:/${remote.share}`, remote.path])
async _mount () {
await fs.ensureDir(this._getRealPath())
return execa('mount', ['-t', 'nfs', '-o', 'vers=3', `${this._remote.host}:${this._remote.path}`, this._getRealPath()])
}
async _sync () {
await this._loadRealMounts()
if (this._matchesRealMount(this._remote) && !this._remote.enabled) {
if (this._matchesRealMount() && !this._remote.enabled) {
try {
await this._umount(this._remote)
} catch (exc) {
this._remote.enabled = true
this._remote.error = exc.message
}
} else if (!this._matchesRealMount(this._remote) && this._remote.enabled) {
} else if (!this._matchesRealMount() && this._remote.enabled) {
try {
await this._mount(this._remote)
await this._mount()
} catch (exc) {
this._remote.enabled = false
this._remote.error = exc.message