Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should force xstat of directory with existing (different) uuid', async () => {
let xstat
await xattr.setAsync(tmpdir, 'user.fruitmix', JSON.stringify({ uuid: uuidArr[0] }))
// xstat = await readXstatAsync(tmpdir)
// expect(xstat.uuid).to.equal(uuidArr[0])
xstat = await forceDriveXstatAsync(tmpdir, uuidArr[2])
expect(xstat).to.deep.equal(pre)
})
})
let xstats = []
await Promise.delay(100)
for (let prop in tree) {
if (tree.hasOwnProperty(prop)) {
let npath = path.join(tmpdir, prop)
// console.log(npath)
if (tree[prop].type === 'directory') {
await mkdirpAsync(npath)
xattr.setAsync(npath, 'user.fruitmix', JSON.stringify({
uuid: tree[prop].uuid
}))
}
else {
await fs.writeFileAsync(npath, '\n')
xattr.setAsync(npath, 'user.fruitmix', JSON.stringify({
uuid: tree[prop].uuid,
magic: 0
}))
}
xstats.push(await readXstatAsync(npath))
}
}
xstats.sort((a, b) => a.name.localeCompare(b.name))
let stats = await fs.lstatAsync(dir)
let mtime = stats.mtime.getTime()
return { mtime, xstats }
}
xc.once('stopped', () => {
// assert state
expect(xc.root.state.constructor.name).to.equal('Finished')
// assert file system and vfs
let attr = JSON.parse(xattr.getSync(path.join(tmptest, 'drives', rootUUID, 'b', 'c'), 'user.fruitmix'))
let dirBC = vfs.findDirByName('c', 'b')
expect(dirBC.uuid).to.equal(attr.uuid)
done()
})
}))
expect(root.uuid).to.equal(rootUUID)
expect(root.name).to.equal(rootUUID)
expect(root.mtime < 0).to.be.true
expect(root.state instanceof Directory.Init).to.be.true
// root is in roots
expect(forest.roots.get(rootUUID)).to.equal(root)
// root is indexed
expect(forest.uuidMap.get(rootUUID)).to.equal(root)
// root is in initDirs
expect(forest.initDirs.has(rootUUID)).to.be.true
// root directory has been stamped
let fattr = xattr.getSync(path.join(tmptest, 'drives', rootUUID), 'user.fruitmix')
let attr = JSON.parse(fattr)
expect(attr).to.deep.equal({ uuid: rootUUID })
// scheduled
expect(forest.dirReadScheduled).to.be.true
// run scheduler
setImmediate(() => {
// root moved to readingDirs
expect(root.state instanceof Directory.Reading).to.be.true
expect(forest.initDirs.has(rootUUID)).to.be.false
expect(forest.readingDirs.has(rootUUID)).to.be.true
// until read done
forest.on('DirReadDone', () => {
// 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')
robotoBold = loadFont(robotoBoldBase64, 'Bold')
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')
write(path, str, callback) {
var tags = str
.trim()
.split(" ")
.reduce((memo, val) => {
if (memo.indexOf(val) === -1) {
memo.push(val);
}
return memo;
}, []);
if (tags.length && tags[0] !== "") {
var plistBuf = bplist.create([tags]);
xattr.set(path, XATTR_KEY, plistBuf, callback);
} else {
xattr.remove(path, XATTR_KEY, callback);
}
var now = new Date();
fs.utimesSync(path, now, now); // update last access/update times
}
});
write(path, str, callback) {
var tags = str
.trim()
.split(" ")
.reduce((memo, val) => {
if (memo.indexOf(val) === -1) {
memo.push(val);
}
return memo;
}, []);
if (tags.length && tags[0] !== "") {
var plistBuf = bplist.create([tags]);
xattr.set(path, XATTR_KEY, plistBuf, callback);
} else {
xattr.remove(path, XATTR_KEY, callback);
}
var now = new Date();
fs.utimesSync(path, now, now); // update last access/update times
}
});
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')
robotoBold = loadFont(robotoBoldBase64, 'Bold')
robotoBlack = loadFont(robotoBlackBase64, 'Black')