@@ -137,8 +137,27 @@ public function beforePut(RequestInterface $request, ResponseInterface $response
137
137
}
138
138
139
139
$ targetFile = $ this ->getTargetFile ($ targetPath );
140
+ $ tempTargetFile = $ this ->uploadFolder ->getChild (self ::TEMP_TARGET );
141
+ $ cacheEntry = $ storage ->getCache ()->get ($ tempTargetFile ->getInternalPath ());
142
+
143
+ [$ destinationDir , $ destinationName ] = Uri \split ($ targetPath );
144
+ /** @var Directory $destinationParent */
145
+ $ destinationParent = $ this ->server ->tree ->getNodeForPath ($ destinationDir );
146
+ $ free = $ storage ->free_space ($ destinationParent ->getInternalPath ());
147
+ $ additionalSize = (int )$ request ->getHeader ('Content-Length ' );
148
+ $ newSize = $ cacheEntry ->getSize () + $ additionalSize ;
149
+ if ($ free >= 0 && ($ cacheEntry ->getSize () > $ free || $ newSize > $ free )) {
150
+ // FIXME: check if needed but might be in responsibility of the clients
151
+ // $this->uploadFolder->delete();
152
+ throw new InsufficientStorage ("Insufficient space in $ targetPath " );
153
+ }
154
+
140
155
$ stream = $ request ->getBodyAsStream ();
141
- $ storage ->putChunkedFilePart ($ targetFile ->getInternalPath (), $ uploadId , (string )$ partId , $ stream , (int )$ request ->getHeader ('Content-Length ' ));
156
+ $ storage ->putChunkedFilePart ($ targetFile ->getInternalPath (), $ uploadId , (string )$ partId , $ stream , $ additionalSize );
157
+ // FIXME add return value to putChunkedFilePart to validate against size
158
+
159
+ $ storage ->getCache ()->update ($ cacheEntry ->getId (), ['size ' => $ cacheEntry ->getSize () + $ additionalSize ]);
160
+ $ storage ->getPropagator ()->propagateChange ($ tempTargetFile ->getInternalPath (), time (), $ additionalSize );
142
161
143
162
$ response ->setStatus (201 );
144
163
return false ;
@@ -155,6 +174,8 @@ public function beforeMove($sourcePath, $destination): bool {
155
174
$ properties = $ this ->server ->getProperties (dirname ($ sourcePath ) . '/ ' , [ self ::OBJECT_UPLOAD_CHUNKTOKEN , self ::OBJECT_UPLOAD_TARGET ]);
156
175
$ targetPath = $ properties [self ::OBJECT_UPLOAD_TARGET ];
157
176
$ uploadId = $ properties [self ::OBJECT_UPLOAD_CHUNKTOKEN ];
177
+
178
+ // FIXME: check if $destination === TARGET
158
179
if (empty ($ targetPath ) || empty ($ uploadId )) {
159
180
throw new PreconditionFailed ('Missing metadata for chunked upload ' );
160
181
}
@@ -172,11 +193,14 @@ public function beforeMove($sourcePath, $destination): bool {
172
193
173
194
$ rootView = new View ();
174
195
if ($ storage ->instanceOfStorage (ObjectStoreStorage::class)) {
175
- $ storage ->processingCallback ('writeChunkedFile ' , function () {
176
- sleep (1 );
177
- \OC_Util::obEnd ();
178
- echo ' ' ;
179
- flush ();
196
+ $ lastTick = time ();
197
+ $ storage ->processingCallback ('writeChunkedFile ' , function () use ($ lastTick ){
198
+ if ($ lastTick < time ()) {
199
+ \OC_Util::obEnd ();
200
+ echo ' ' ;
201
+ flush ();
202
+ }
203
+ $ lastTick = time ();
180
204
});
181
205
}
182
206
0 commit comments