parent
bd9d36fb2f
commit
e4732baf83
@ -0,0 +1,13 @@
|
||||
var os = require('os')
|
||||
var path = require('path')
|
||||
var fs = require('fs')
|
||||
|
||||
var mnt = path.join(os.tmpdir(), 'fuse-bindings-' + process.pid + '-' + Date.now())
|
||||
|
||||
try {
|
||||
fs.mkdirSync(mnt)
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
module.exports = mnt
|
@ -0,0 +1,11 @@
|
||||
module.exports = function (st) {
|
||||
return {
|
||||
mtime: st.mtime || new Date(),
|
||||
atime: st.atime || new Date(),
|
||||
ctime: st.ctime || new Date(),
|
||||
size: st.size !== undefined ? st.size : 0,
|
||||
mode: st.mode === 'dir' ? 16877 : (st.mode === 'file' ? 33188 : (st.mode === 'link' ? 41453 : st.mode)),
|
||||
uid: st.uid !== undefined ? st.uid : process.getuid(),
|
||||
gid: st.gid !== undefined ? st.gid : process.getgid()
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
var mnt = require('./fixtures/mnt')
|
||||
var stat = require('./fixtures/stat')
|
||||
var fuse = require('../')
|
||||
var tape = require('tape')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
|
||||
tape('readlink', function (t) {
|
||||
var ops = {
|
||||
force: true,
|
||||
readdir: function (path, cb) {
|
||||
if (path === '/') return cb(null, ['hello', 'link'])
|
||||
return cb(fuse.ENOENT)
|
||||
},
|
||||
readlink: function (path, cb) {
|
||||
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 }))
|
||||
return cb(fuse.ENOENT)
|
||||
},
|
||||
open: function (path, flags, cb) {
|
||||
cb(0, 42)
|
||||
},
|
||||
read: function (path, fd, buf, len, pos, cb) {
|
||||
var str = 'hello world'.slice(pos, pos + len)
|
||||
if (!str) return cb(0)
|
||||
buf.write(str)
|
||||
return cb(str.length)
|
||||
}
|
||||
}
|
||||
|
||||
fuse.mount(mnt, ops, function (err) {
|
||||
t.error(err, 'no error')
|
||||
|
||||
fs.lstat(path.join(mnt, 'link'), function (err, stat) {
|
||||
t.error(err, 'no error')
|
||||
t.same(stat.size, 5, 'correct size')
|
||||
|
||||
fs.stat(path.join(mnt, 'hello'), function (err, stat) {
|
||||
t.error(err, 'no error')
|
||||
t.same(stat.size, 11, 'correct size')
|
||||
|
||||
fs.readlink(path.join(mnt, 'link'), function (err, dest) {
|
||||
t.error(err, 'no error')
|
||||
t.same(dest, 'hello', 'link resolves')
|
||||
|
||||
fs.readFile(path.join(mnt, 'link'), function (err, buf) {
|
||||
t.error(err, 'no error')
|
||||
t.same(buf, new Buffer('hello world'), 'can read link content')
|
||||
|
||||
fuse.unmount(mnt, function () {
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
@ -0,0 +1,43 @@
|
||||
var mnt = require('./fixtures/mnt')
|
||||
var fuse = require('../')
|
||||
var tape = require('tape')
|
||||
|
||||
tape('mount', function (t) {
|
||||
fuse.mount(mnt, { force: true }, function (err) {
|
||||
t.error(err, 'no error')
|
||||
t.ok(true, 'works')
|
||||
fuse.unmount(mnt, function () {
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
tape('mount + unmount + mount', function (t) {
|
||||
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) {
|
||||
t.error(err, 'no error')
|
||||
t.ok(true, 'works')
|
||||
fuse.unmount(mnt, function () {
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
tape('mnt point must exist', function (t) {
|
||||
fuse.mount(mnt + '.does-not-exist', {}, function (err) {
|
||||
t.ok(err, 'had error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape('mnt point must be directory', function (t) {
|
||||
fuse.mount(__filename, {}, function (err) {
|
||||
t.ok(err, 'had error')
|
||||
t.end()
|
||||
})
|
||||
})
|
@ -0,0 +1,64 @@
|
||||
const tape = require('tape')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const concat = require('concat-stream')
|
||||
|
||||
const Fuse = require('../')
|
||||
const mnt = require('./fixtures/mnt')
|
||||
const stat = require('./fixtures/stat')
|
||||
|
||||
tape('read', function (t) {
|
||||
var ops = {
|
||||
force: true,
|
||||
readdir: function (path, cb) {
|
||||
if (path === '/') return cb(null, ['test'])
|
||||
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 }))
|
||||
return cb(fuse.ENOENT)
|
||||
},
|
||||
open: function (path, flags, cb) {
|
||||
cb(0, 42)
|
||||
},
|
||||
release: function (path, fd, cb) {
|
||||
t.same(fd, 42, 'fd was passed to release')
|
||||
cb(0)
|
||||
},
|
||||
read: function (path, fd, buf, len, pos, cb) {
|
||||
var str = 'hello world'.slice(pos, pos + len)
|
||||
if (!str) return cb(0)
|
||||
buf.write(str)
|
||||
return cb(str.length)
|
||||
}
|
||||
}
|
||||
|
||||
const fuse = new Fuse(mnt, ops, { debug: true })
|
||||
|
||||
fuse.mount(function (err) {
|
||||
t.error(err, 'no error')
|
||||
|
||||
fs.readFile(path.join(mnt, 'test'), function (err, buf) {
|
||||
t.error(err, 'no error')
|
||||
t.same(buf, new Buffer('hello world'), 'read file')
|
||||
|
||||
fs.readFile(path.join(mnt, 'test'), function (err, buf) {
|
||||
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) {
|
||||
t.same(buf, new Buffer('hello'), 'partial read file')
|
||||
|
||||
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 () {
|
||||
t.end()
|
||||
})
|
||||
}))
|
||||
}))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
@ -0,0 +1,54 @@
|
||||
var mnt = require('./fixtures/mnt')
|
||||
var stat = require('./fixtures/stat')
|
||||
var fuse = require('../')
|
||||
var tape = require('tape')
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
|
||||
tape('write', function (t) {
|
||||
var created = false
|
||||
var data = new Buffer(1024)
|
||||
var size = 0
|
||||
|
||||
var ops = {
|
||||
force: true,
|
||||
readdir: function (path, cb) {
|
||||
if (path === '/') return cb(null, created ? ['hello'] : [])
|
||||
return cb(fuse.ENOENT)
|
||||
},
|
||||
truncate: function (path, size, cb) {
|
||||
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 }))
|
||||
return cb(fuse.ENOENT)
|
||||
},
|
||||
create: function (path, flags, cb) {
|
||||
t.ok(!created, 'file not created yet')
|
||||
created = true
|
||||
cb(0, 42)
|
||||
},
|
||||
release: function (path, fd, cb) {
|
||||
cb(0)
|
||||
},
|
||||
write: function (path, fd, buf, len, pos, cb) {
|
||||
buf.slice(0, len).copy(data, pos)
|
||||
size = Math.max(pos + len, size)
|
||||
cb(buf.length)
|
||||
}
|
||||
}
|
||||
|
||||
fuse.mount(mnt, ops, function (err) {
|
||||
t.error(err, 'no error')
|
||||
|
||||
fs.writeFile(path.join(mnt, 'hello'), 'hello world', function (err) {
|
||||
t.error(err, 'no error')
|
||||
t.same(data.slice(0, size), new Buffer('hello world'), 'data was written')
|
||||
|
||||
fuse.unmount(mnt, function () {
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in new issue