@@ -293,8 +293,16 @@ FS.TempStore.createWriteStream = function(fileObj, options) {
293293 setObj [ 'keys.' + chunkNum ] = result . fileKey ;
294294 tracker . update ( selector , { $set : setObj } ) ;
295295
296+
297+ var temp = tracker . findOne ( selector ) ;
298+
299+ if ( ! temp ) {
300+ FS . debug && console . log ( 'NOT FOUND FROM TEMPSTORE => EXIT (REMOVED)' ) ;
301+ return ;
302+ }
303+
296304 // Get updated chunkCount
297- var chunkCount = FS . Utility . size ( tracker . findOne ( selector ) . keys ) ;
305+ var chunkCount = FS . Utility . size ( temp . keys ) ;
298306
299307 // Progress
300308 self . emit ( 'progress' , fileObj , chunkNum , chunkCount , chunkSum , result ) ;
@@ -304,6 +312,9 @@ FS.TempStore.createWriteStream = function(fileObj, options) {
304312 // We no longer need the chunk info
305313 var modifier = { $set : { } , $unset : { chunkCount : 1 , chunkSum : 1 , chunkSize : 1 } } ;
306314
315+ if ( ! fileObj . instance_id )
316+ modifier . $set . instance_id = process . env . COLLECTIONFS_ENV_NAME_UNIQUE_ID ? process . env [ process . env . COLLECTIONFS_ENV_NAME_UNIQUE_ID ] : process . env . METEOR_PARENT_PID ;
317+
307318 // Check if the file has been uploaded before
308319 if ( typeof fileObj . uploadedAt === 'undefined' ) {
309320 // We set the uploadedAt date
@@ -324,8 +335,14 @@ FS.TempStore.createWriteStream = function(fileObj, options) {
324335 // XXX is emitting "ready" necessary?
325336 self . emit ( 'ready' , fileObj , chunkCount , result ) ;
326337 } else {
327- // Update the chunkCount on the fileObject
328- fileObj . update ( { $set : { chunkCount : chunkCount } } ) ;
338+
339+ var modifier = { $set : { } } ;
340+ if ( ! fileObj . instance_id )
341+ modifier . $set . instance_id = process . env . COLLECTIONFS_ENV_NAME_UNIQUE_ID ? process . env [ process . env . COLLECTIONFS_ENV_NAME_UNIQUE_ID ] : process . env . METEOR_PARENT_PID ;
342+
343+ modifier . $set . chunkCount = chunkCount ;
344+
345+ fileObj . update ( modifier ) ;
329346 }
330347 } ) ;
331348
0 commit comments