From 0d48cd8fc80f66e564f9719c73c9f164f7041815 Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Wed, 18 Sep 2019 18:44:54 +0200 Subject: [PATCH] Bug fixes --- example.js | 13 ++++++++++++- fuse-native.c | 16 ++++++++-------- index.js | 16 +++++++++++++--- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/example.js b/example.js index ff4b6a0..419576b 100644 --- a/example.js +++ b/example.js @@ -3,7 +3,18 @@ const Fuse = require('./') const ops = { readdir: function (path, cb) { console.log('readdir(%s)', path) - if (path === '/') return process.nextTick(cb, 0, ['test']) + if (path === '/') return process.nextTick(cb, 0, ['test'], [ + { + mtime: new Date(), + atime: new Date(), + ctime: new Date(), + nlink: 1, + size: 12, + mode: 33188, + uid: process.getuid ? process.getuid() : 0, + gid: process.getgid ? process.getgid() : 0 + } + ]) return process.nextTick(cb, 0) }, /* diff --git a/fuse-native.c b/fuse-native.c index 103b93e..65e82a0 100644 --- a/fuse-native.c +++ b/fuse-native.c @@ -170,8 +170,7 @@ static fuse_thread_locals_t* get_thread_locals (); // TODO: Extract into a separate file. static void fin (napi_env env, void *fin_data, void* fin_hint) { - printf("finaliser is run\n"); - // exit(0); + //exit(0); } static void to_timespec (struct timespec* ts, uint32_t* int_ptr) { @@ -273,18 +272,16 @@ FUSE_METHOD(access, 2, 0, (const char *path, int mode), { }, {}) -FUSE_METHOD(open, 3, 1, (const char *path, struct fuse_file_info *info), { +FUSE_METHOD(open, 2, 1, (const char *path, struct fuse_file_info *info), { l->path = path; l->info = info; }, { napi_create_string_utf8(env, l->path, NAPI_AUTO_LENGTH, &(argv[2])); if (l->info != NULL) { - napi_create_uint32(env, l->info->fh, &(argv[3])); - napi_create_uint32(env, l->info->flags, &(argv[4])); + napi_create_uint32(env, l->info->flags, &(argv[3])); } else { napi_create_uint32(env, 0, &(argv[3])); - napi_create_uint32(env, 0, &(argv[4])); } }, { @@ -331,7 +328,7 @@ FUSE_METHOD(create, 2, 1, (const char *path, mode_t mode, struct fuse_file_info } }) -FUSE_METHOD(utimens, 2, 0, (const char *path, const struct timespec tv[2]), { +FUSE_METHOD(utimens, 3, 0, (const char *path, const struct timespec tv[2]), { l->path = path; from_timespec(&tv[0], l->atim); from_timespec(&tv[1], l->mtim); @@ -444,6 +441,8 @@ FUSE_METHOD(readdir, 1, 2, (const char *path, void *buf, fuse_fill_dir_t filler, struct stat st; populate_stat(stats_array, &st); + // TODO: It turns out readdirplus likely won't work with FUSE 29... + // Metadata caching between readdir/getattr will be enabled when we upgrade fuse-shared-library int err = l->readdir_filler((char *) l->buf, name, (struct stat *) &st, 0); if (err == 1) { break; @@ -958,7 +957,8 @@ NAPI_METHOD(fuse_native_unmount) { NAPI_ARGV_BUFFER_CAST(fuse_thread_t *, ft, 1); if (ft != NULL && ft->mounted) { - pthread_join(ft->thread, NULL); + // TODO: Investigate why the FUSE thread is not always killed after fusermount. + // pthread_join(ft->thread, NULL); } uv_unref((uv_handle_t *) &(ft->async)); diff --git a/index.js b/index.js index 93e5897..57a98e0 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const path = require('path') const { exec } = require('child_process') const Nanoresource = require('nanoresource') +const { beforeMount, beforeUnmount, configure, unconfigure, isConfigured } = require('fuse-shared-library') + const binding = require('node-gyp-build')(__dirname) const IS_OSX = os.platform() === 'darwin' @@ -251,13 +253,14 @@ class Fuse extends Nanoresource { } _close (cb) { + if (this._closed) return process.nextTick(cb, null) const self = this const mnt = JSON.stringify(this.mnt) - const cmd = IS_OSX ? `diskutil umount ${mnt}` : `fusermount -q -u ${mnt}` + const cmd = IS_OSX ? `diskutil umount ${mnt}` : `fusermount -uz ${mnt}` - exec(cmd, err => { + exec(cmd, (err, stdout, stderr) => { if (err) return cb(err) - return nativeUnmount() + nativeUnmount() }) function nativeUnmount () { @@ -659,6 +662,13 @@ Fuse.EDQUOT = -122 Fuse.ENOMEDIUM = -123 Fuse.EMEDIUMTYPE = -124 +// Forward configuration functions through the exported class. +Fuse.beforeMount = beforeMount +Fuse.beforeUnmount = beforeUnmount +Fuse.configure = configure +Fuse.unconfigure = unconfigure +Fuse.isConfigured = isConfigured + module.exports = Fuse function getStatfsArray (statfs) {