mirror of
https://github.com/fuse-friends/fuse-native
synced 2024-10-27 18:34:01 +00:00
Standardized
This commit is contained in:
parent
8fb3334d7a
commit
b9d24f6812
9
index.js
9
index.js
@ -75,7 +75,7 @@ exports.mount = function (mnt, ops, opts, cb) {
|
|||||||
if (!ops.getattr) { // we need this for unmount to work on osx
|
if (!ops.getattr) { // we need this for unmount to work on osx
|
||||||
ops.getattr = function (path, cb) {
|
ops.getattr = function (path, cb) {
|
||||||
if (path !== '/') return cb(fuse.EPERM)
|
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]
|
const cb = arguments[arguments.length - 1]
|
||||||
var called = false
|
var called = false
|
||||||
|
|
||||||
|
if (destroyed) {
|
||||||
|
if (!called) return cb(exports.EIO)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const idx = pending.indexOf(null)
|
const idx = pending.indexOf(null)
|
||||||
|
|
||||||
const cbInfo = { cb, tick: 0 }
|
const cbInfo = { cb, tick: 0 }
|
||||||
pending[idx === -1 ? pending.length : idx] = cbInfo
|
pending[idx === -1 ? pending.length : idx] = cbInfo
|
||||||
|
|
||||||
try {
|
try {
|
||||||
op.apply(null, [...Array.prototype.slice.call(arguments, 0, -1), safeCb])
|
op(...[...Array.prototype.slice.call(arguments, 0, -1), safeCb])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!cb[TIMED_OUT] && !called) return cb(exports.EIO)
|
if (!cb[TIMED_OUT] && !called) return cb(exports.EIO)
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ tape('readlink', function (t) {
|
|||||||
cb(0, 'hello')
|
cb(0, 'hello')
|
||||||
},
|
},
|
||||||
getattr: function (path, cb) {
|
getattr: function (path, cb) {
|
||||||
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
|
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
|
||||||
if (path === '/hello') return cb(null, stat({mode: 'file', size: 11}))
|
if (path === '/hello') return cb(null, stat({ mode: 'file', size: 11 }))
|
||||||
if (path === '/link') return cb(null, stat({mode: 'link', size: 5}))
|
if (path === '/link') return cb(null, stat({ mode: 'link', size: 5 }))
|
||||||
return cb(fuse.ENOENT)
|
return cb(fuse.ENOENT)
|
||||||
},
|
},
|
||||||
open: function (path, flags, cb) {
|
open: function (path, flags, cb) {
|
||||||
|
@ -3,7 +3,7 @@ var fuse = require('../')
|
|||||||
var tape = require('tape')
|
var tape = require('tape')
|
||||||
|
|
||||||
tape('mount', function (t) {
|
tape('mount', function (t) {
|
||||||
fuse.mount(mnt, {force: true}, function (err) {
|
fuse.mount(mnt, { force: true }, function (err) {
|
||||||
t.error(err, 'no error')
|
t.error(err, 'no error')
|
||||||
t.ok(true, 'works')
|
t.ok(true, 'works')
|
||||||
fuse.unmount(mnt, function () {
|
fuse.unmount(mnt, function () {
|
||||||
@ -13,11 +13,11 @@ tape('mount', function (t) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
tape('mount + unmount + 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.error(err, 'no error')
|
||||||
t.ok(true, 'works')
|
t.ok(true, 'works')
|
||||||
fuse.unmount(mnt, function () {
|
fuse.unmount(mnt, function () {
|
||||||
fuse.mount(mnt, {force: true}, function (err) {
|
fuse.mount(mnt, { force: true }, function (err) {
|
||||||
t.error(err, 'no error')
|
t.error(err, 'no error')
|
||||||
t.ok(true, 'works')
|
t.ok(true, 'works')
|
||||||
fuse.unmount(mnt, function () {
|
fuse.unmount(mnt, function () {
|
||||||
|
@ -14,8 +14,8 @@ tape('read', function (t) {
|
|||||||
return cb(fuse.ENOENT)
|
return cb(fuse.ENOENT)
|
||||||
},
|
},
|
||||||
getattr: function (path, cb) {
|
getattr: function (path, cb) {
|
||||||
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
|
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
|
||||||
if (path === '/test') return cb(null, stat({mode: 'file', size: 11}))
|
if (path === '/test') return cb(null, stat({ mode: 'file', size: 11 }))
|
||||||
return cb(fuse.ENOENT)
|
return cb(fuse.ENOENT)
|
||||||
},
|
},
|
||||||
open: function (path, flags, cb) {
|
open: function (path, flags, cb) {
|
||||||
@ -44,10 +44,10 @@ tape('read', function (t) {
|
|||||||
t.error(err, 'no error')
|
t.error(err, 'no error')
|
||||||
t.same(buf, new Buffer('hello world'), 'read file again')
|
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')
|
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')
|
t.same(buf, new Buffer('world'), 'partial read file + start offset')
|
||||||
|
|
||||||
fuse.unmount(mnt, function () {
|
fuse.unmount(mnt, function () {
|
||||||
|
@ -20,8 +20,8 @@ tape('write', function (t) {
|
|||||||
cb(0)
|
cb(0)
|
||||||
},
|
},
|
||||||
getattr: function (path, cb) {
|
getattr: function (path, cb) {
|
||||||
if (path === '/') return cb(null, stat({mode: 'dir', size: 4096}))
|
if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 }))
|
||||||
if (path === '/hello' && created) return cb(null, stat({mode: 'file', size: size}))
|
if (path === '/hello' && created) return cb(null, stat({ mode: 'file', size: size }))
|
||||||
return cb(fuse.ENOENT)
|
return cb(fuse.ENOENT)
|
||||||
},
|
},
|
||||||
create: function (path, flags, cb) {
|
create: function (path, flags, cb) {
|
||||||
|
Loading…
Reference in New Issue
Block a user