37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const Fuse = require('fuse-native')
|
|
const Errors = require('../../shared/Errors')
|
|
const Message = require('../../shared/Message')
|
|
const connector = require('../connector')
|
|
|
|
module.exports = exports = function (path, cb) {
|
|
|
|
connector.send(
|
|
Message.route('fs.readdir')
|
|
.data({ path })
|
|
.expect_response(msg => {
|
|
if ( msg.error() ) {
|
|
if ( msg.error() === Errors.NodeDoesNotExist ) {
|
|
return process.nextTick(cb, Fuse.ENOENT)
|
|
} else {
|
|
return process.nextTick(cb, Fuse.ENODATA)
|
|
}
|
|
}
|
|
|
|
const { nodes } = msg.data()
|
|
|
|
const names = nodes.map(x => {
|
|
const name = x.pied_name
|
|
|
|
x.mtime = new Date(x.mtime)
|
|
x.atime = new Date(x.atime)
|
|
x.ctime = new Date(x.ctime)
|
|
delete x.pied_name
|
|
|
|
return name
|
|
})
|
|
|
|
return process.nextTick(cb, 0, names, nodes)
|
|
})
|
|
)
|
|
}
|