Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const readXstatAsync = async target => {
let attr, dirty, stats = await fs.lstatAsync(target)
if(!stats.isFile() && !stats.isDirectory())
throw Object.assign(new Error('not a directory or file'), { code: 'ENOTDIRORFILE' })
try{
attr = await JSON.parse(xattr.getAsync(target, FRUITMIX))
if(attr.hasOwnProperty('owner')) {
validateOldFormat()
dirty = true
delete attr.owner
if(attr.writelist === null) delete attr.writelist
if(attr.readlist === null) delete attr.readlist
if(stats.isFile())
attr.magic = attr.magic ? parseMagic(attr.magic) : fileMagic(attr.magic)
} else
validateNewFormat(attr)
// drop hash if outdated
if(stats.isFile() && attr.htime && attr.htime !== stats.mtime) {
dirty = true
it('should calculate hash if file has no xattr', async () => {
try {
await xattr.getAsync(filepath, 'user.fruitmix')
} catch(e) {
expect(e.code).to.be.equal('ENODATA')
}
let hash = await repo.storeFileAsync(filepath)
expect(hash).to.equal(sha256)
})
throw new E.EINVAL()
}
if(segments[start] === 1){
console.log('该段以上传', segments)
throw new E.EEXIST()
}
let segmentSize = attr.segmentsize
let segmentLength = segments.length > start + 1 ? segmentSize : (attr.size - start * segmentSize)
let position = attr.segmentsize * start
let updater = new SegmentUpdater(fpath, req, position, segmentHash, segmentLength)
await updater.startAsync()
try{
attr = JSON.parse(await xattr.getAsync(fpath, FILEMAP))
attr.segments[start] = 1
await xattr.setAsync(fpath, FILEMAP, JSON.stringify(attr))
if(attr.segments.includes(0)) return false
let fname = await autoRenameAsync(attr.userUUID, attr.dirUUID, attr.name)
console.log('----------------' + fname)
await moveFileMapAsync(attr.userUUID, attr.dirUUID, fname, fpath, attr.sha256)
return true
}catch(e){
console.log(e)
throw e
}
}