mirror of
https://github.com/fuse-friends/fuse-native
synced 2024-10-27 18:34:01 +00:00
Add mkdir option + update README
This commit is contained in:
parent
9528eeff48
commit
2f6d2054fe
@ -73,6 +73,8 @@ Create a new `Fuse` object.
|
|||||||
```
|
```
|
||||||
displayFolder: 'Folder Name', // Add a name/icon to the mount volume on OSX,
|
displayFolder: 'Folder Name', // Add a name/icon to the mount volume on OSX,
|
||||||
debug: false, // Enable detailed tracing of operations.
|
debug: false, // Enable detailed tracing of operations.
|
||||||
|
force: false, // Attempt to unmount a the mountpoint before remounting.
|
||||||
|
mkdir: false // Create the mountpoint before mounting.
|
||||||
```
|
```
|
||||||
Additionally, all (FUSE-specific options)[http://man7.org/linux/man-pages/man8/mount.fuse.8.html] will be passed to the underlying FUSE module (though we use camel casing instead of snake casing).
|
Additionally, all (FUSE-specific options)[http://man7.org/linux/man-pages/man8/mount.fuse.8.html] will be passed to the underlying FUSE module (though we use camel casing instead of snake casing).
|
||||||
|
|
||||||
|
21
index.js
21
index.js
@ -142,6 +142,7 @@ class Fuse extends Nanoresource {
|
|||||||
this.timeout = opts.timeout || DEFAULT_TIMEOUT
|
this.timeout = opts.timeout || DEFAULT_TIMEOUT
|
||||||
|
|
||||||
this._force = !!opts.force
|
this._force = !!opts.force
|
||||||
|
this._mkdir = !!opts.mkdir
|
||||||
this._thread = null
|
this._thread = null
|
||||||
this._handlers = this._makeHandlerArray()
|
this._handlers = this._makeHandlerArray()
|
||||||
|
|
||||||
@ -281,9 +282,23 @@ class Fuse extends Nanoresource {
|
|||||||
const implemented = self._getImplementedArray()
|
const implemented = self._getImplementedArray()
|
||||||
|
|
||||||
return fs.stat(self.mnt, (err, stat) => {
|
return fs.stat(self.mnt, (err, stat) => {
|
||||||
if (err) return cb(new Error('Mountpoint does not exist'))
|
if (err && err.errno !== -2) return cb(err)
|
||||||
|
if (err) {
|
||||||
|
if (!self._mkdir) return cb(new Error('Mountpoint does not exist'))
|
||||||
|
return fs.mkdir(self.mnt, { recursive: true }, err => {
|
||||||
|
if (err) return cb(err)
|
||||||
|
fs.stat(self.mnt, (err, stat) => {
|
||||||
|
if (err) return cb(err)
|
||||||
|
return onexists(stat)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
if (!stat.isDirectory()) return cb(new Error('Mountpoint is not a directory'))
|
if (!stat.isDirectory()) return cb(new Error('Mountpoint is not a directory'))
|
||||||
return fs.stat(path.join(self.mnt, '..'), (_, parent) => {
|
return onexists(stat)
|
||||||
|
})
|
||||||
|
|
||||||
|
function onexists (stat) {
|
||||||
|
fs.stat(path.join(self.mnt, '..'), (_, parent) => {
|
||||||
if (parent && parent.dev !== stat.dev) return cb(new Error('Mountpoint in use'))
|
if (parent && parent.dev !== stat.dev) return cb(new Error('Mountpoint in use'))
|
||||||
try {
|
try {
|
||||||
// TODO: asyncify
|
// TODO: asyncify
|
||||||
@ -292,7 +307,7 @@ class Fuse extends Nanoresource {
|
|||||||
return cb(err)
|
return cb(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,10 +4,12 @@ const path = require('path')
|
|||||||
const concat = require('concat-stream')
|
const concat = require('concat-stream')
|
||||||
|
|
||||||
const Fuse = require('../')
|
const Fuse = require('../')
|
||||||
const mnt = require('./fixtures/mnt')
|
const createMountpoint = require('./fixtures/mnt')
|
||||||
const stat = require('./fixtures/stat')
|
const stat = require('./fixtures/stat')
|
||||||
const { unmount } = require('./helpers')
|
const { unmount } = require('./helpers')
|
||||||
|
|
||||||
|
const mnt = createMountpoint()
|
||||||
|
|
||||||
tape('read and write big file', function (t) {
|
tape('read and write big file', function (t) {
|
||||||
let size = 0
|
let size = 0
|
||||||
const reads = [0, 4 * 1024 * 1024 * 1024, 6 * 1024 * 1024 * 1024]
|
const reads = [0, 4 * 1024 * 1024 * 1024, 6 * 1024 * 1024 * 1024]
|
||||||
|
8
test/fixtures/mnt.js
vendored
8
test/fixtures/mnt.js
vendored
@ -2,12 +2,18 @@ var os = require('os')
|
|||||||
var path = require('path')
|
var path = require('path')
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
|
||||||
|
function create (opts = {}) {
|
||||||
var mnt = path.join(os.tmpdir(), 'fuse-bindings-' + process.pid + '-' + Date.now())
|
var mnt = path.join(os.tmpdir(), 'fuse-bindings-' + process.pid + '-' + Date.now())
|
||||||
|
|
||||||
|
if (!opts.doNotCreate) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(mnt)
|
fs.mkdirSync(mnt)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = mnt
|
return mnt
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = create
|
||||||
|
@ -4,9 +4,11 @@ const path = require('path')
|
|||||||
const { unmount } = require('./helpers')
|
const { unmount } = require('./helpers')
|
||||||
|
|
||||||
const Fuse = require('../')
|
const Fuse = require('../')
|
||||||
const mnt = require('./fixtures/mnt')
|
const createMountpoint = require('./fixtures/mnt')
|
||||||
const stat = require('./fixtures/stat')
|
const stat = require('./fixtures/stat')
|
||||||
|
|
||||||
|
const mnt = createMountpoint()
|
||||||
|
|
||||||
tape('readlink', function (t) {
|
tape('readlink', function (t) {
|
||||||
var ops = {
|
var ops = {
|
||||||
force: true,
|
force: true,
|
||||||
|
26
test/misc.js
26
test/misc.js
@ -1,10 +1,12 @@
|
|||||||
const mnt = require('./fixtures/mnt')
|
const createMountpoint = require('./fixtures/mnt')
|
||||||
const tape = require('tape')
|
const tape = require('tape')
|
||||||
const { spawnSync } = require('child_process')
|
const { spawnSync } = require('child_process')
|
||||||
|
|
||||||
const Fuse = require('../')
|
const Fuse = require('../')
|
||||||
const { unmount } = require('./helpers')
|
const { unmount } = require('./helpers')
|
||||||
|
|
||||||
|
const mnt = createMountpoint()
|
||||||
|
|
||||||
tape('mount', function (t) {
|
tape('mount', function (t) {
|
||||||
const fuse = new Fuse(mnt, {}, { force: true })
|
const fuse = new Fuse(mnt, {}, { force: true })
|
||||||
fuse.mount(function (err) {
|
fuse.mount(function (err) {
|
||||||
@ -111,6 +113,28 @@ tape('mounting over a broken mountpoint with force succeeds', function (t) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tape('mounting without mkdir option and a nonexistent mountpoint fails', function (t) {
|
||||||
|
const nonexistentMnt = createMountpoint({ doNotCreate: true })
|
||||||
|
|
||||||
|
const fuse = new Fuse(nonexistentMnt, {}, { debug: false })
|
||||||
|
fuse.mount(function (err) {
|
||||||
|
t.true(err, 'could not mount')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('mounting with mkdir option and a nonexistent mountpoint succeeds', function (t) {
|
||||||
|
const nonexistentMnt = createMountpoint({ doNotCreate: true })
|
||||||
|
|
||||||
|
const fuse = new Fuse(nonexistentMnt, {}, { debug: false, mkdir: true })
|
||||||
|
fuse.mount(function (err) {
|
||||||
|
t.error(err, 'no error')
|
||||||
|
unmount(fuse, function (err) {
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
tape('static unmounting', function (t) {
|
tape('static unmounting', function (t) {
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
@ -4,10 +4,12 @@ const path = require('path')
|
|||||||
const concat = require('concat-stream')
|
const concat = require('concat-stream')
|
||||||
|
|
||||||
const Fuse = require('../')
|
const Fuse = require('../')
|
||||||
const mnt = require('./fixtures/mnt')
|
const createMountpoint = require('./fixtures/mnt')
|
||||||
const stat = require('./fixtures/stat')
|
const stat = require('./fixtures/stat')
|
||||||
const { unmount } = require('./helpers')
|
const { unmount } = require('./helpers')
|
||||||
|
|
||||||
|
const mnt = createMountpoint()
|
||||||
|
|
||||||
tape('read', function (t) {
|
tape('read', function (t) {
|
||||||
var ops = {
|
var ops = {
|
||||||
force: true,
|
force: true,
|
||||||
|
@ -3,9 +3,11 @@ const { unmount } = require('./helpers')
|
|||||||
const tape = require('tape')
|
const tape = require('tape')
|
||||||
|
|
||||||
const Fuse = require('../')
|
const Fuse = require('../')
|
||||||
const mnt = require('./fixtures/mnt')
|
const createMountpoint = require('./fixtures/mnt')
|
||||||
const stat = require('./fixtures/stat')
|
const stat = require('./fixtures/stat')
|
||||||
|
|
||||||
|
const mnt = createMountpoint()
|
||||||
|
|
||||||
tape('statfs', function (t) {
|
tape('statfs', function (t) {
|
||||||
const ops = {
|
const ops = {
|
||||||
force: true,
|
force: true,
|
||||||
|
@ -3,10 +3,12 @@ const fs = require('fs')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const Fuse = require('../')
|
const Fuse = require('../')
|
||||||
const mnt = require('./fixtures/mnt')
|
const createMountpoint = require('./fixtures/mnt')
|
||||||
const stat = require('./fixtures/stat')
|
const stat = require('./fixtures/stat')
|
||||||
const { unmount } = require('./helpers')
|
const { unmount } = require('./helpers')
|
||||||
|
|
||||||
|
const mnt = createMountpoint()
|
||||||
|
|
||||||
tape('write', function (t) {
|
tape('write', function (t) {
|
||||||
var created = false
|
var created = false
|
||||||
var data = Buffer.alloc(1024)
|
var data = Buffer.alloc(1024)
|
||||||
|
Loading…
Reference in New Issue
Block a user