From 15848fc696c7fa09f9f7391d7c9eb95e5a470cdb Mon Sep 17 00:00:00 2001
From: Laurent Cozic <laurent@cozic.net>
Date: Sun, 28 Jan 2018 17:37:51 +0000
Subject: [PATCH] Closing a resource is async

---
 .../lib/services/EncryptionService.js         | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/ReactNativeClient/lib/services/EncryptionService.js b/ReactNativeClient/lib/services/EncryptionService.js
index 96e8b38a97..01599f289f 100644
--- a/ReactNativeClient/lib/services/EncryptionService.js
+++ b/ReactNativeClient/lib/services/EncryptionService.js
@@ -378,8 +378,8 @@ class EncryptionService {
 			read: async (size) => {
 				return this.fsDriver().readFileChunk(reader.handle, size, encoding);
 			},
-			close: () => {
-				this.fsDriver().close(reader.handle);
+			close: async () => {
+				await this.fsDriver().close(reader.handle);
 			},
 		};
 		return reader;
@@ -412,9 +412,9 @@ class EncryptionService {
 		let source = await this.fileReader_(srcPath, 'base64');
 		let destination = await this.fileWriter_(destPath, 'ascii');
 
-		const cleanUp = () => {
-			if (source) source.close();
-			if (destination) destination.close();
+		const cleanUp = async () => {
+			if (source) await source.close();
+			if (destination) await destination.close();
 			source = null;
 			destination = null;
 		}
@@ -428,16 +428,16 @@ class EncryptionService {
 			throw error;
 		}
 
-		cleanUp();
+		await cleanUp();
 	}
 
 	async decryptFile(srcPath, destPath) {
 		let source = await this.fileReader_(srcPath, 'ascii');
 		let destination = await this.fileWriter_(destPath, 'base64');
 
-		const cleanUp = () => {
-			if (source) source.close();
-			if (destination) destination.close();
+		const cleanUp = async () => {
+			if (source) await source.close();
+			if (destination) await destination.close();
 			source = null;
 			destination = null;
 		}
@@ -451,7 +451,7 @@ class EncryptionService {
 			throw error;
 		}
 
-		cleanUp();
+		await cleanUp();
 	}
 
 	decodeHeaderVersion_(hexaByte) {