Skip to content

Commit 7dbaa1e

Browse files
committed
Make the quota functions async
1 parent 2c51be3 commit 7dbaa1e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/utils.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,23 @@ function routeResolvedFile (router, path, file, appendFileName = true) {
251251
* may store or Infinity if no limit
252252
*/
253253

254-
function getQuota (root, serverUri) {
254+
async function getQuota (root, serverUri) {
255255
const filename = path.join(root, 'settings/serverSide.ttl')
256256
var quota = Infinity
257257
var prefs
258258
try {
259-
prefs = fs.readFileSync(filename, 'utf8')
259+
prefs = await _asyncReadfile(filename)
260260
} catch (error) {
261261
debug('Setting no quota. While reading serverSide.ttl, got ' + error)
262262
return Infinity
263263
}
264264
var graph = $rdf.graph()
265265
const storageUri = serverUri + '/'
266-
$rdf.parse(prefs, graph, storageUri, 'text/turtle')
266+
try {
267+
$rdf.parse(prefs, graph, storageUri, 'text/turtle')
268+
} catch (error) {
269+
throw new Error('Failed to parse serverSide.ttl, got ' + error)
270+
}
267271
const lit = graph.each($rdf.sym(storageUri), ns.solid('storageQuota'), undefined)[0]
268272
if (lit) {
269273
quota = lit.value
@@ -285,17 +289,19 @@ function getQuota (root, serverUri) {
285289
}
286290

287291
async function overQuota (root, serverUri) {
288-
let quota = getQuota(root, serverUri)
292+
let quota = await getQuota(root, serverUri)
289293
console.log(root, quota)
290294
if (quota === Infinity) {
291295
return false
292296
}
293297
var actualSize = await _asyncGetSize(root)
294-
console.log(actualSize, quota)
295298
return (actualSize > quota)
296299
}
297300

298301
function _asyncGetSize (root) {
299302
return util.promisify(getSize)(root)
300303
}
301304

305+
function _asyncReadfile (filename) {
306+
return util.promisify(fs.readFile)(filename, 'utf-8')
307+
}

0 commit comments

Comments
 (0)