Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
read: function(path, stats, callback) {
if (!xattr)
return callback(
new Error(
"xattr no longer available, probably due to package being deactivated while in transit"
)
);
xattr.get(path, XATTR_KEY, function(err, plistBuf) {
if (err) {
if (err.code === "ENOATTR") {
callback(null, null); // no xattrs set; return empty list
} else {
callback(err); // e.g. file path does not exist or such
}
} else {
bplist.parseBuffer(plistBuf, function(err, list) {
if (err) {
callback(err);
} else {
callback(null, list[0]);
}
});
}
});
import fs from 'fs';
import xattr from 'fs-xattr';
let target = '/home/laraine/Projects/appifi/testpic/20141213.jpg'
xattr.get(target, 'user.fruitmix', (err, attr) => {
console.log(JSON.parse(attr))
console.log(JSON.parse(attr).hasOwnProperty('uuid'))
console.log(JSON.parse(attr).hasOwnProperty('hash'))
console.log(JSON.parse(attr).hasOwnProperty('htime'))
console.log(JSON.parse(attr).hasOwnProperty('hash') === JSON.parse(attr).hasOwnProperty('htime'))
})
clone('tmptest/a/b', stats.uuid, 'tmptest/c/d', (err, xstat) => {
if (err) return done(err)
xattr.get('tmptest/c/d', 'user.fruitmix', err => {
expect(err.code).to.equal('ENODATA')
done()
})
})
})
readXstat(picpath, (err, xstat) => {
if(err) return done(err)
xattr.get(picpath, FRUITMIX, (err, attr) => {
if(err) return done(err)
let attrObj = JSON.parse(attr)
expect(attrObj.htime).to.equal(stats.mtime.getTime())
expect(xstat.uuid).to.deep.equal(uuid_1)
expect(xstat.isFile()).to.be.true
expect(xstat.writelist).to.be.an('undefined')
expect(xstat.readlist).to.be.an('undefined')
expect(xstat.hash).to.deep.equal(hash_1)
expect(xstat.htime).to.be.an('undefined')
expect(xstat.magic).to.deep.equal('JPEG')
expect(xstat.abspath).to.deep.equal(picpath)
done()
})
})
})
copyXattr(copypath, filepath, err => {
if(err) return done(err)
xattr.get(copypath, FRUITMIX, (err, attr) => {
if(err) return done(err)
let attrObj = JSON.parse(attr)
expect(attrObj.uuid).to.deep.equal(uuid_1)
expect(attrObj.hash).to.deep.equal(hash_1)
done()
})
})
})
const readFileMap = (userUUID, taskId, callback) => {
let fpath = path.join(paths.get('filemap'), userUUID, taskId)
if(fs.existsSync(fpath)){
xattr.get(fpath, FILEMAP, (err, attr) => {
if(err) return callback(err)
try{
return callback(null, Object.assign({}, JSON.parse(attr), {taskid: taskId}))
}catch(e){
callback(e)
}
})
}else
return callback(new Error('filemap not find'))
}