Skip to content

Commit 2c51be3

Browse files
committed
Improve the callback async handling, thanks @megoth
1 parent 53fe1b1 commit 2c51be3

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

lib/utils.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports.overQuota = overQuota
1818

1919
const fs = require('fs-extra')
2020
const path = require('path')
21+
const util = require('util')
2122
const $rdf = require('rdflib')
2223
const from = require('from2')
2324
const url = require('url')
@@ -284,19 +285,17 @@ function getQuota (root, serverUri) {
284285
}
285286

286287
async function overQuota (root, serverUri) {
287-
var actualSize = await _asyncGetSize(root)
288288
let quota = getQuota(root, serverUri)
289-
console.log(root)
289+
console.log(root, quota)
290+
if (quota === Infinity) {
291+
return false
292+
}
293+
var actualSize = await _asyncGetSize(root)
290294
console.log(actualSize, quota)
291295
return (actualSize > quota)
292296
}
293297

294298
function _asyncGetSize (root) {
295-
return new Promise((resolve, reject) =>
296-
getSize(root, (err) => {
297-
reject(err)
298-
},
299-
(size) => {
300-
resolve(size)
301-
}))
299+
return util.promisify(getSize)(root)
302300
}
301+

test/integration/quota-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ describe('Get Quota', function () {
2525

2626
describe('Check if over Quota', function () {
2727
it('Check the quota', function () {
28-
expect(overQuota(path.join('test/resources/', root), 'https://localhost')).to.be.false()
28+
expect(overQuota(path.join('test/resources/', root), 'https://localhost')).to.be.true
2929
})
3030
it('Check the quota with non-existant file', function () {
31-
expect(overQuota(path.join('nowhere/', root), 'https://localhost')).to.be.false()
31+
expect(overQuota(path.join('nowhere/', root), 'https://localhost')).to.be.false
3232
})
3333
it('Check the quota when the predicate is not present', function () {
3434
expect(overQuota('test/resources/accounts-acl/quota', 'https://localhost')).to.be.false()

0 commit comments

Comments
 (0)