From d05b6fb890135e719667ef4181212712b2758e72 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Wed, 11 Nov 2015 14:44:15 +0200 Subject: [PATCH] writeTextSync will now unlock the file when it is done writing --- file-system/file-system.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/file-system/file-system.ts b/file-system/file-system.ts index 95197fa93..f9ebd41b6 100644 --- a/file-system/file-system.ts +++ b/file-system/file-system.ts @@ -245,18 +245,22 @@ export class File extends FileSystemEntity { public writeTextSync(content: string, onError?: (error: any) => any, encoding?: string): void { this.checkAccess(); - this[fileLockedProperty] = true; - - var that = this; - var localError = function (error) { - that[fileLockedProperty] = false; - if (onError) { - onError(error); - } - }; - - // TODO: Asyncronous - getFileAccess().writeText(this.path, content, localError, encoding); + try { + this[fileLockedProperty] = true; + + var that = this; + var localError = function (error) { + that[fileLockedProperty] = false; + if (onError) { + onError(error); + } + }; + + // TODO: Asyncronous + getFileAccess().writeText(this.path, content, localError, encoding); + } finally { + this[fileLockedProperty] = false; + } } private checkAccess() {