1
0
mirror of https://github.com/fuse-friends/fuse-native synced 2024-10-27 18:34:01 +00:00

Standardized

This commit is contained in:
Andrew Osheroff 2019-07-16 13:46:43 +02:00
parent 8fb3334d7a
commit b9d24f6812
5 changed files with 20 additions and 15 deletions

View File

@ -75,7 +75,7 @@ exports.mount = function (mnt, ops, opts, cb) {
if (!ops.getattr) { // we need this for unmount to work on osx
ops.getattr = function (path, cb) {
if (path !== '/') return cb(fuse.EPERM)
cb(null, {mtime: new Date(0), atime: new Date(0), ctime: new Date(0), mode: 16877, size: 4096})
cb(null, { mtime: new Date(0), atime: new Date(0), ctime: new Date(0), mode: 16877, size: 4096 })
}
}
@ -156,13 +156,18 @@ function wrapSafe (ops, timeout) {
const cb = arguments[arguments.length - 1]
var called = false
if (destroyed) {
if (!called) return cb(exports.EIO)
return
}
const idx = pending.indexOf(null)
const cbInfo = { cb, tick: 0 }
const cbInfo = { cb, tick: 0 }
pending[idx === -1 ? pending.length : idx] = cbInfo
try {
op.apply(null, [...Array.prototype.slice.call(arguments, 0, -1), safeCb])
op(...[...Array.prototype.slice.call(arguments, 0, -1), safeCb])
} catch (err) {
if (!cb[TIMED_OUT] && !called) return cb(exports.EIO)
}

View File

@ -16,9 +16,9 @@ tape('readlink', function (t) {
cb(0, 'hello')
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
if (path === '/hello') return cb(null, stat({mode: 'file', size: 11}))
if (path === '/link') return cb(null, stat({mode: 'link', size: 5}))
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
if (path === '/hello') return cb(null, stat({ mode: 'file', size: 11 }))
if (path === '/link') return cb(null, stat({ mode: 'link', size: 5 }))
return cb(fuse.ENOENT)
},
open: function (path, flags, cb) {

View File

@ -3,7 +3,7 @@ var fuse = require('../')
var tape = require('tape')
tape('mount', function (t) {
fuse.mount(mnt, {force: true}, function (err) {
fuse.mount(mnt, { force: true }, function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
@ -13,11 +13,11 @@ tape('mount', function (t) {
})
tape('mount + unmount + mount', function (t) {
fuse.mount(mnt, {force: true}, function (err) {
fuse.mount(mnt, { force: true }, function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {
fuse.mount(mnt, {force: true}, function (err) {
fuse.mount(mnt, { force: true }, function (err) {
t.error(err, 'no error')
t.ok(true, 'works')
fuse.unmount(mnt, function () {

View File

@ -14,8 +14,8 @@ tape('read', function (t) {
return cb(fuse.ENOENT)
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
if (path === '/test') return cb(null, stat({mode: 'file', size: 11}))
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
if (path === '/test') return cb(null, stat({ mode: 'file', size: 11 }))
return cb(fuse.ENOENT)
},
open: function (path, flags, cb) {
@ -44,10 +44,10 @@ tape('read', function (t) {
t.error(err, 'no error')
t.same(buf, new Buffer('hello world'), 'read file again')
fs.createReadStream(path.join(mnt, 'test'), {start: 0, end: 4}).pipe(concat(function (buf) {
fs.createReadStream(path.join(mnt, 'test'), { start: 0, end: 4 }).pipe(concat(function (buf) {
t.same(buf, new Buffer('hello'), 'partial read file')
fs.createReadStream(path.join(mnt, 'test'), {start: 6, end: 10}).pipe(concat(function (buf) {
fs.createReadStream(path.join(mnt, 'test'), { start: 6, end: 10 }).pipe(concat(function (buf) {
t.same(buf, new Buffer('world'), 'partial read file + start offset')
fuse.unmount(mnt, function () {

View File

@ -20,8 +20,8 @@ tape('write', function (t) {
cb(0)
},
getattr: function (path, cb) {
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
if (path === '/hello' && created) return cb(null, stat({mode: 'file', size: size}))
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
if (path === '/hello' && created) return cb(null, stat({ mode: 'file', size: size }))
return cb(fuse.ENOENT)
},
create: function (path, flags, cb) {