Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createRoot(uuid) {
let dirPath = path.join(this.driveDir, uuid)
let stats, attr = { uuid }
try {
mkdirp.sync(dirPath)
stats = fs.lstatSync(dirPath)
// this is tricky but works
xattr.setSync(dirPath, 'user.fruitmix', JSON.stringify(attr))
} catch (e) {
console.log(e)
return
}
let name = path.basename(dirPath)
let xstat = {
uuid: attr.uuid,
type: 'directory',
name,
mtime: stats.mtime.getTime()
}
return this.forest.createRoot(uuid, xstat)
}
// test xxhash
const XXHASH = require('xxhash')
console.log('test xxhash: ' + XXHASH.hash(Buffer.from('hello'), 1234))
}
if (xattrBase64) {
mkdirp.sync(dir)
let decode = Buffer.from(xattrBase64.toString(), 'base64')
fs.writeFileSync(path.join(dir, 'xattr.node'), decode)
// test xattr
const XATTR = require('fs-xattr')
XATTR.setSync(dir, 'user.foo', 'bar')
console.log('test xattr: ' + XATTR.getSync(dir, 'user.foo'))
XATTR.removeSync(dir, 'user.foo')
}
function loadFont (base64, name) {
if (base64)
return Buffer.from(base64, 'base64')
else
return fs.readFileSync('./public/stylesheets/Roboto-' + name + '-webfont.woff')
}
robotoThin = loadFont(robotoThinBase64, 'Thin')
robotoLight = loadFont(robotoLightBase64, 'Light')
robotoRegular = loadFont(robotoRegularBase64, 'Regular')
robotoMedium = loadFont(robotoMediumBase64, 'Medium')
getUnsupportedError: function() {
try {
// Due to being optionalDependencies they might not exist, if that's the case do nothing and just return
require("bplist");
var xattr = require("fs-xattr");
// Filesystem might not support xattrs, verify before continuing
var OS = require("os");
var Path = require("path");
var tmpPath = Path.join(
OS.tmpdir(),
"verify-nv-tags" + process.hrtime().toString()
);
fs.writeFileSync(tmpPath, "");
xattr.setSync(tmpPath, XATTR_KEY, "test writing xattrs");
fs.unlinkSync(tmpPath);
} catch (err) {
return err;
}
},
return process.nextTick(() => callback(err))
}
if (drive.type !== 'private') {
let err = new Error('permission denied')
err.status = 403 // TODO 404?
return process.nextTick(() => callback(err))
}
if (props.op && props.op === 'format') {
let tmpDir = path.join(this.tmpDir, UUID.v4())
let dirPath = path.join(this.driveDir, root.uuid)
try {
mkdirp.sync(tmpDir)
let attr = JSON.parse(xattr.getSync(dirPath, 'user.fruitmix'))
xattr.setSync(tmpDir, 'user.fruitmix', JSON.stringify(attr))
rimraf.sync(dirPath)
fs.renameSync(tmpDir, dirPath)
return dir.read(callback)
} catch (e) {
return callback(e)
}
}
return callback(new Error('invalid op'))
}
}
const clean = (dir, dirContext, entry, callback) => {
let xattrType = dirContext.type
let fpath = path.join(dir, entry)
xattr.setSync(fpath, xattrType, JSON.stringify({}))
fs.lstatSync(fpath).isFile() ? callback() : callback(dirContext)
}
this.visit(this.srcPath, { type: 'user.fruitmix'}, clean, callback)
mkfile(dstFilePath, tmp, xstat.hash, policy, (err, xstats, resolved) => {
rimraf(tmp, () => {})
if (err) return callback(err)
if (!xstat || (policy[0] === 'skip' && xstat && resolved[0])) return
else {
try {
let attr = JSON.parse(xattr.getSync(srcFilePath, 'user.fruitmix'))
attr.uuid = xstats.uuid
xattr.setSync(dstFilePath, 'user.fruitmix', JSON.stringify(attr))
} catch (e) {
if (e.code !== 'ENODATA') return callback(e)
}
}
callback(null)
})
})
mkfile(dstFilePath, tmp, xstat.hash, policy, (err, xstats, resolved) => {
rimraf(tmp, () => {})
if (err) return callback(err)
if (!xstat || (policy[0] === 'skip' && xstat && resolved[0])) return
else {
try {
let attr = JSON.parse(xattr.getSync(srcFilePath, 'user.fruitmix'))
attr.uuid = xstats.uuid
xattr.setSync(dstFilePath, 'user.fruitmix', JSON.stringify(attr))
} catch (e) {
if (e.code !== 'ENODATA') return callback(e)
}
}
callback(null)
})
})