Skip to content

Commit

Permalink
all tests pass except clean unmounting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewosh committed Aug 1, 2019
1 parent 1be6242 commit 54a5d6c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
8 changes: 6 additions & 2 deletions fuse-native.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,12 @@ FUSE_METHOD(readlink, 1, 1, (const char *path, char *linkname, size_t len), {
}, {
napi_create_string_utf8(env, l->path, NAPI_AUTO_LENGTH, &(argv[2]));
}, {
NAPI_ARGV_UTF8(linkname, 1024, 2)
strncpy(linkname, l->linkname, l->len);
printf("right before napi_argv_utf8\n");
NAPI_ARGV_UTF8(linkname, l->len, 2)
printf("right after napi_argv_utf8, len: %i, linkname: %s \n", l->len, linkname);
strncpy(l->linkname, linkname, l->len);
printf("after copy: l->linkname: %s\n", l->linkname);
ret = 0;
})

FUSE_METHOD(chown, 3, 0, (const char *path, uid_t uid, gid_t gid), {
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class Fuse {
return
}
this.ops.getattr(path, (err, stat) => {
console.log('USER GETATT RESULT, path:', path, 'err:', err, 'stat:', stat)
if (err) return signal(err, getStatArray())
return signal(0, getStatArray(stat))
})
Expand Down Expand Up @@ -298,7 +299,6 @@ class Fuse {

_open (signal, path, flags) {
this.ops.open(path, flags, (err, fd) => {
console.log('SIGNALLING WITH FD:', fd)
return signal(err, fd)
})
}
Expand Down Expand Up @@ -480,9 +480,7 @@ class Fuse {
mount (cb) {
const opts = this._fuseOptions()
console.log('mounting at %s with opts: %s', this.mnt, opts)
console.log('handlers:', this._handlers)
const implemented = this._getImplementedArray()
console.log('implemented:', implemented)
fs.stat(this.mnt, (err, stat) => {
if (err) return cb(new Error('Mountpoint does not exist'))
if (!stat.isDirectory()) return cb(new Error('Mountpoint is not a directory'))
Expand Down
22 changes: 12 additions & 10 deletions test/links.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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')
const tape = require('tape')
const fs = require('fs')
const path = require('path')

const Fuse = require('../')
const mnt = require('./fixtures/mnt')
const stat = require('./fixtures/stat')

tape('readlink', function (t) {
var ops = {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, ['hello', 'link'])
return cb(fuse.ENOENT)
return cb(Fuse.ENOENT)
},
readlink: function (path, cb) {
cb(0, 'hello')
Expand All @@ -19,7 +20,7 @@ tape('readlink', function (t) {
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)
return cb(Fuse.ENOENT)
},
open: function (path, flags, cb) {
cb(0, 42)
Expand All @@ -32,7 +33,8 @@ tape('readlink', function (t) {
}
}

fuse.mount(mnt, ops, function (err) {
const fuse = new Fuse(mnt, ops, { debug: true })
fuse.mount(function (err) {
t.error(err, 'no error')

fs.lstat(path.join(mnt, 'link'), function (err, stat) {
Expand All @@ -51,7 +53,7 @@ tape('readlink', function (t) {
t.error(err, 'no error')
t.same(buf, new Buffer('hello world'), 'can read link content')

fuse.unmount(mnt, function () {
fuse.unmount( function () {
t.end()
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ tape('read', function (t) {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, ['test'])
return cb(fuse.ENOENT)
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)
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)
},
Expand All @@ -35,7 +36,6 @@ tape('read', function (t) {
}

const fuse = new Fuse(mnt, ops, { debug: true })

fuse.mount(function (err) {
t.error(err, 'no error')

Expand All @@ -53,7 +53,7 @@ tape('read', function (t) {
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 () {
fuse.unmount(function () {
t.end()
})
}))
Expand Down
24 changes: 13 additions & 11 deletions test/write.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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')
const tape = require('tape')
const fs = require('fs')
const path = require('path')

const Fuse = require('../')
const mnt = require('./fixtures/mnt')
const stat = require('./fixtures/stat')

tape('write', function (t) {
var created = false
Expand All @@ -14,15 +15,15 @@ tape('write', function (t) {
force: true,
readdir: function (path, cb) {
if (path === '/') return cb(null, created ? ['hello'] : [])
return cb(fuse.ENOENT)
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)
if (path === '/hello' && created) return cb(0, stat({ mode: 'file', size: size }))
return cb(Fuse.ENOENT)
},
create: function (path, flags, cb) {
t.ok(!created, 'file not created yet')
Expand All @@ -39,14 +40,15 @@ tape('write', function (t) {
}
}

fuse.mount(mnt, ops, function (err) {
const fuse = new Fuse(mnt, ops, { debug: true })
fuse.mount(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 () {
fuse.unmount(function () {
t.end()
})
})
Expand Down

0 comments on commit 54a5d6c

Please sign in to comment.