@@ -290,7 +290,7 @@ protected void removeFilePathRecursively(String oid, String path) {
290290 /**
291291 * Utility function used, to remove a specific file
292292 **/
293- protected boolean removeFilePathOnce (String oid , String path ) {
293+ protected boolean removeFilePath (String oid , String path ) {
294294 // Lets build the query for the "root file"
295295 Bson query = null ;
296296
@@ -300,16 +300,16 @@ protected boolean removeFilePathOnce(String oid, String path) {
300300 // Remove matching path
301301 query = Filters .eq ("filename" , oid +"/" +path );
302302
303- // Lets prepare the search
304- GridFSFindIterable search = gridFSBucket .find (query ). limit ( 1 ) ;
303+ // Lets prepare the search (removes all versions)
304+ GridFSFindIterable search = gridFSBucket .find (query );
305305
306306 // Lets iterate the search result, and return true on an item
307307 try (MongoCursor <GridFSFile > cursor = search .iterator ()) {
308- if (cursor .hasNext ()) {
308+ while (cursor .hasNext ()) {
309309 GridFSFile fileObj = cursor .next ();
310310 gridFSBucket .delete (fileObj .getId ());
311- return true ;
312311 }
312+ return true ;
313313 }
314314
315315 // removal didn't occur
@@ -378,7 +378,7 @@ public void backend_fileWriteInputStream(String oid, String filepath, InputStrea
378378
379379 // Prepare the upload options
380380 GridFSUploadOptions opt = (new GridFSUploadOptions ()).metadata (metadata );
381- gridFSBucket .uploadFromStream (oid , data , opt );
381+ gridFSBucket .uploadFromStream (fullPath , data , opt );
382382 } catch (Exception e ) {
383383 throw new RuntimeException (e );
384384 } finally {
@@ -450,7 +450,7 @@ public boolean backend_fileExist(String oid, String filepath) {
450450
451451 @ Override
452452 public void backend_removeFile (String oid , String filepath ) {
453- removeFilePathOnce (oid , cleanFilePath (filepath ));
453+ removeFilePath (oid , cleanFilePath (filepath ));
454454 }
455455
456456 // Folder Pathing support
0 commit comments