From 54a5d6c0b3d310a10b1669b767318439a130dd12 Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Fri, 2 Aug 2019 00:19:00 +0200 Subject: [PATCH] all tests pass except clean unmounting --- fuse-native.c | 8 ++++++-- index.js | 4 +--- test/links.js | 22 ++++++++++++---------- test/read.js | 8 ++++---- test/write.js | 24 +++++++++++++----------- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/fuse-native.c b/fuse-native.c index 683b954..38484d9 100644 --- a/fuse-native.c +++ b/fuse-native.c @@ -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), { diff --git a/index.js b/index.js index 1da1cb1..9e95906 100644 --- a/index.js +++ b/index.js @@ -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)) }) @@ -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) }) } @@ -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')) diff --git a/test/links.js b/test/links.js index 19f02e1..411bcb4 100644 --- a/test/links.js +++ b/test/links.js @@ -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') @@ -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) @@ -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) { @@ -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() }) }) diff --git a/test/read.js b/test/read.js index 09c3caf..efcb980 100644 --- a/test/read.js +++ b/test/read.js @@ -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) }, @@ -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') @@ -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() }) })) diff --git a/test/write.js b/test/write.js index da15402..12102bf 100644 --- a/test/write.js +++ b/test/write.js @@ -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 @@ -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') @@ -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() }) })