|
1 | 1 | "use strict"; |
2 | 2 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +var stream_1 = require("stream"); |
3 | 4 | var LockScope_1 = require("../../../resource/lock/LockScope"); |
4 | 5 | var LockType_1 = require("../../../resource/lock/LockType"); |
5 | 6 | var LockKind_1 = require("../../../resource/lock/LockKind"); |
@@ -154,10 +155,21 @@ var FileSystem = (function () { |
154 | 155 | this.emit('before-create', ctx, path, { type: type, createIntermediates: createIntermediates }); |
155 | 156 | issuePrivilegeCheck(this, ctx, path, 'canWrite', callback, function () { |
156 | 157 | var go = function () { |
157 | | - _this._create(path, { |
158 | | - context: ctx, |
159 | | - type: type |
160 | | - }, callback); |
| 158 | + ctx.server.options.storageManager.evaluateCreate(ctx, _this, path, type, function (size) { |
| 159 | + ctx.server.options.storageManager.reserve(ctx, _this, size, function (reserved) { |
| 160 | + if (!reserved) |
| 161 | + return callback(Errors_1.Errors.InsufficientStorage); |
| 162 | + _this._create(path, { |
| 163 | + context: ctx, |
| 164 | + type: type |
| 165 | + }, function (e) { |
| 166 | + if (e) |
| 167 | + ctx.server.options.storageManager.reserve(ctx, _this, -size, function () { return callback(e); }); |
| 168 | + else |
| 169 | + callback(); |
| 170 | + }); |
| 171 | + }); |
| 172 | + }); |
161 | 173 | }; |
162 | 174 | _this.isLocked(ctx, path, function (e, locked) { |
163 | 175 | if (e || locked) |
@@ -239,7 +251,19 @@ var FileSystem = (function () { |
239 | 251 | _this._delete(path, { |
240 | 252 | context: ctx, |
241 | 253 | depth: depth |
242 | | - }, callback); |
| 254 | + }, function (e) { |
| 255 | + if (!e) { |
| 256 | + _this.type(ctx, path, function (e, type) { |
| 257 | + ctx.server.options.storageManager.evaluateCreate(ctx, _this, path, type, function (size) { |
| 258 | + ctx.server.options.storageManager.reserve(ctx, _this, -size, function () { |
| 259 | + callback(); |
| 260 | + }); |
| 261 | + }); |
| 262 | + }); |
| 263 | + } |
| 264 | + else |
| 265 | + callback(e); |
| 266 | + }); |
243 | 267 | }); |
244 | 268 | }); |
245 | 269 | }); |
@@ -279,14 +303,59 @@ var FileSystem = (function () { |
279 | 303 | _this.isLocked(ctx, path, function (e, isLocked) { |
280 | 304 | if (e || isLocked) |
281 | 305 | return callback(e ? e : Errors_1.Errors.Locked); |
282 | | - var go = function (callback) { |
| 306 | + var finalGo = function (callback) { |
283 | 307 | _this._openWriteStream(path, { |
284 | 308 | context: ctx, |
285 | 309 | estimatedSize: estimatedSize, |
286 | 310 | targetSource: targetSource, |
287 | 311 | mode: mode |
288 | 312 | }, function (e, wStream) { return callback(e, wStream, created); }); |
289 | 313 | }; |
| 314 | + var go = function (callback) { |
| 315 | + _this.size(ctx, path, true, function (e, size) { |
| 316 | + ctx.server.options.storageManager.evaluateContent(ctx, _this, size, function (sizeStored) { |
| 317 | + if (estimatedSize === undefined || estimatedSize === null || estimatedSize.constructor === Number && estimatedSize <= 0) { |
| 318 | + ctx.server.options.storageManager.available(ctx, _this, function (available) { |
| 319 | + if (available === -1) |
| 320 | + return finalGo(callback); |
| 321 | + if (available === 0) |
| 322 | + return callback(Errors_1.Errors.InsufficientStorage); |
| 323 | + var nb = 0; |
| 324 | + finalGo(function (e, wStream, created) { |
| 325 | + if (e) |
| 326 | + return callback(e, wStream, created); |
| 327 | + var stream = new stream_1.Transform({ |
| 328 | + transform: function (chunk, encoding, callback) { |
| 329 | + nb += chunk.length; |
| 330 | + if (nb > available) |
| 331 | + callback(Errors_1.Errors.InsufficientStorage); |
| 332 | + else |
| 333 | + callback(null, chunk, encoding); |
| 334 | + } |
| 335 | + }); |
| 336 | + stream.pipe(wStream); |
| 337 | + stream.on('finish', function () { |
| 338 | + ctx.server.options.storageManager.reserve(ctx, _this, nb, function (reserved) { |
| 339 | + if (!reserved) |
| 340 | + stream.emit('error', Errors_1.Errors.InsufficientStorage); |
| 341 | + }); |
| 342 | + }); |
| 343 | + callback(e, stream, created); |
| 344 | + }); |
| 345 | + }); |
| 346 | + } |
| 347 | + else { |
| 348 | + ctx.server.options.storageManager.evaluateContent(ctx, _this, estimatedSize, function (estimatedSizeStored) { |
| 349 | + ctx.server.options.storageManager.reserve(ctx, _this, estimatedSizeStored - sizeStored, function (reserved) { |
| 350 | + if (!reserved) |
| 351 | + return callback(Errors_1.Errors.InsufficientStorage); |
| 352 | + finalGo(callback); |
| 353 | + }); |
| 354 | + }); |
| 355 | + } |
| 356 | + }); |
| 357 | + }); |
| 358 | + }; |
290 | 359 | var createAndGo = function (intermediates) { |
291 | 360 | _this.create(ctx, path, CommonTypes_1.ResourceType.File, intermediates, function (e) { |
292 | 361 | if (e) |
@@ -671,8 +740,25 @@ var FileSystem = (function () { |
671 | 740 | }); |
672 | 741 | }, |
673 | 742 | getProperties: function (callback, byCopy) { |
| 743 | + var _this = this; |
674 | 744 | issuePrivilegeCheck(fs, ctx, pPath, 'canReadProperties', callback, function () { |
675 | | - pm.getProperties(callback, byCopy); |
| 745 | + pm.getProperties(function (e, bag) { |
| 746 | + if (!bag) |
| 747 | + return callback(e, bag); |
| 748 | + ctx.server.options.storageManager.available(ctx, _this, function (availableSize) { |
| 749 | + if (availableSize === -1) |
| 750 | + return callback(e, bag); |
| 751 | + ctx.server.options.storageManager.reserved(ctx, _this, function (reservedSize) { |
| 752 | + bag['DAV:quota-available-bytes'] = { |
| 753 | + value: availableSize.toString() |
| 754 | + }; |
| 755 | + bag['DAV:quota-used-bytes'] = { |
| 756 | + value: reservedSize.toString() |
| 757 | + }; |
| 758 | + callback(e, bag); |
| 759 | + }); |
| 760 | + }); |
| 761 | + }, byCopy); |
676 | 762 | }); |
677 | 763 | } |
678 | 764 | }); |
|
0 commit comments