@@ -10,6 +10,7 @@ const utils = require('./utils')
1010const error = require ( './http-error' )
1111const stringToStream = require ( './utils' ) . stringToStream
1212const serialize = require ( './utils' ) . serialize
13+ const overQuota = require ( './utils' ) . overQuota
1314const extend = require ( 'extend' )
1415const rimraf = require ( 'rimraf' )
1516const ldpContainer = require ( './ldp-container' )
@@ -266,24 +267,33 @@ class LDP {
266267 return callback ( error ( 409 ,
267268 'PUT not supported on containers, use POST instead' ) )
268269 }
269- // First, create the enclosing directory, if necessary
270- const dirName = path . dirname ( filePath )
271- mkdirp ( dirName , ( err ) => {
272- if ( err ) {
273- debug . handlers ( 'PUT -- Error creating directory: ' + err )
274- return callback ( error ( err ,
275- 'Failed to create the path to the new resource' ) )
270+
271+ // First check if we are above quota
272+ overQuota ( root , this . serverUri ) . then ( ( isOverQuota ) => {
273+ if ( isOverQuota ) {
274+ return callback ( error ( 413 ,
275+ 'User has exceeded their storage quota' ) )
276276 }
277- // Directory created, now write the file
278- const file = stream . pipe ( fs . createWriteStream ( filePath ) )
279- file . on ( 'error' , function ( ) {
280- callback ( error ( 500 , 'Error writing data' ) )
281- } )
282- file . on ( 'finish' , function ( ) {
283- debug . handlers ( 'PUT -- Wrote data to: ' + filePath )
284- callback ( null )
277+
278+ // Second, create the enclosing directory, if necessary
279+ const dirName = path . dirname ( filePath )
280+ mkdirp ( dirName , ( err ) => {
281+ if ( err ) {
282+ debug . handlers ( 'PUT -- Error creating directory: ' + err )
283+ return callback ( error ( err ,
284+ 'Failed to create the path to the new resource' ) )
285+ }
286+ // Directory created, now write the file
287+ const file = stream . pipe ( fs . createWriteStream ( filePath ) )
288+ file . on ( 'error' , function ( ) {
289+ callback ( error ( 500 , 'Error writing data' ) )
290+ } )
291+ file . on ( 'finish' , function ( ) {
292+ debug . handlers ( 'PUT -- Wrote data to: ' + filePath )
293+ callback ( null )
294+ } )
285295 } )
286- } )
296+ } ) . catch ( ( ) => { throw error ( 500 , 'Error finding user quota' ) } )
287297 }
288298
289299 exists ( hostname , path , callback ) {
0 commit comments