Procházet zdrojové kódy

clean up tmp after import

mizozobu před 6 roky
rodič
revize
25261f9cc6
1 změnil soubory, kde provedl 5 přidání a 1 odebrání
  1. 5 1
      src/server/service/import.js

+ 5 - 1
src/server/service/import.js

@@ -111,7 +111,8 @@ class ImportService {
     let failedIds = [];
     let unorderedBulkOp = Model.collection.initializeUnorderedBulkOp();
 
-    const readStream = fs.createReadStream(path.join(this.baseDir, `${collectionName}.json`), { encoding: this.encoding });
+    const tmpJson = path.join(this.baseDir, `${collectionName}.json`);
+    const readStream = fs.createReadStream(tmpJson, { encoding: this.encoding });
     const jsonStream = readStream.pipe(JSONStream.parse('*'));
 
     jsonStream.on('data', async(document) => {
@@ -153,6 +154,9 @@ class ImportService {
 
     // streamToPromise(jsonStream) throws error, so await readStream instead
     await streamToPromise(readStream);
+
+    // clean up tmp directory
+    fs.unlinkSync(tmpJson);
   }
 
   /**