Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
err.status = 403 // TODO 404?
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'))
}
}
mkdir('tmptest/a/b', [,'rename'], (err, xstat, resolved) => {
if (err) return done(err)
let attr = JSON.parse(xattr.getSync('tmptest/a/b', 'user.fruitmix'))
let stat = fs.lstatSync('tmptest/a/b')
expect(xstat).to.deep.equal({
uuid: attr.uuid,
type: 'directory',
name: 'b',
mtime: stat.mtime.getTime()
})
expect(resolved).to.deep.equal([false, false])
done()
})
})
mvdir('tmptest/a/b', 'tmptest/c/d', ['skip'], (err, xstat, resolved) => {
if (err) return done(err)
let attr = JSON.parse(xattr.getSync('tmptest/c/d', 'user.fruitmix'))
let stat = fs.lstatSync('tmptest/c/d')
expect(xstat).to.deep.equal({
uuid: attr.uuid,
type: 'directory',
name: 'd',
mtime: stat.mtime.getTime()
})
expect(resolved).to.deep.equal([true, false])
done()
})
})
mvfile('tmptest/a/b', 'tmptest/c/d', ['skip', 'skip'], (err, xstat, resolved) => {
let attr = JSON.parse(xattr.getSync('tmptest/c/d', 'user.fruitmix'))
let stat = fs.lstatSync('tmptest/c/d')
expect(xstat).to.deep.equal({
uuid: attr.uuid,
type: 'file',
name: 'd',
mtime: stat.mtime.getTime(),
size: stat.size,
magic: Magic.ver
})
expect(resolved).to.deep.equal([true, false])
done()
})
})
mkfile('tmptest/a/b', 'tmptest/tmp', null, [,'rename'], (err, xstat, resolved) => {
if (err) return done(err)
let attr = JSON.parse(xattr.getSync('tmptest/a/b (2)', 'user.fruitmix'))
let stat = fs.lstatSync('tmptest/a/b (2)')
expect(attr).to.deep.equal({
uuid: attr.uuid,
magic: 'JPEG'
})
expect(xstat).to.deep.equal({
uuid: attr.uuid,
type: 'file',
name: 'b (2)',
mtime: stat.mtime.getTime(),
size: stat.size,
magic: 'JPEG'
})
expect(resolved).to.deep.equal([false, true])
done()
})
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)
})
})
return callback(null, list.map( f => {
try{
let attr = JSON.parse(xattr.getSync(path.join(folderPath, f), FILEMAP))
if(attr) return Object.assign({}, attr, {taskid: f})
return undefined
}catch(e){
return undefined
}
}))
})