Skip to content

Commit 72231cb

Browse files
author
Fatme
authored
Merge pull request #3917 from NativeScript/fatme/fix-android-livesync
chore: sync correctly deleted files on android devices
2 parents 9fca19d + 45b1a28 commit 72231cb

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

lib/definitions/livesync.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ interface IAndroidLivesyncTool {
465465
* @param filePaths - Array of files that will be removed.
466466
* @returns {Promise<boolean[]>}
467467
*/
468-
removeFiles(filePaths: string[]): Promise<void[]>;
468+
removeFiles(filePaths: string[]): Promise<void>;
469469
/**
470470
* Sends doSyncOperation that will be handled by the runtime.
471471
* @param options

lib/services/livesync/android-device-livesync-sockets-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class AndroidDeviceSocketsLiveSyncService extends AndroidDeviceLiveSyncSe
4848
return result;
4949
} catch (e) {
5050
this.livesyncTool.end();
51+
throw e;
5152
}
5253
}
5354

lib/services/livesync/android-livesync-tool.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,27 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
104104
}
105105

106106
public async removeFile(filePath: string): Promise<void> {
107-
this.verifyActiveConnection();
108-
const filePathData = this.getFilePathData(filePath);
109-
const headerBuffer = Buffer.alloc(PROTOCOL_OPERATION_LENGTH_SIZE +
110-
SIZE_BYTE_LENGTH +
111-
filePathData.filePathLengthSize +
112-
filePathData.filePathLengthBytes);
113-
114-
let offset = 0;
115-
offset += headerBuffer.write(AndroidLivesyncTool.DELETE_FILE_OPERATION.toString(), offset, PROTOCOL_OPERATION_LENGTH_SIZE);
116-
offset = headerBuffer.writeInt8(filePathData.filePathLengthSize, offset);
117-
offset += headerBuffer.write(filePathData.filePathLengthString, offset, filePathData.filePathLengthSize);
118-
headerBuffer.write(filePathData.relativeFilePath, offset, filePathData.filePathLengthBytes);
119-
const hash = crypto.createHash("md5").update(headerBuffer).digest();
120-
121-
await this.writeToSocket(headerBuffer);
122-
await this.writeToSocket(hash);
107+
this.verifyActiveConnection();
108+
const filePathData = this.getFilePathData(filePath);
109+
const headerBuffer = Buffer.alloc(PROTOCOL_OPERATION_LENGTH_SIZE +
110+
SIZE_BYTE_LENGTH +
111+
filePathData.filePathLengthSize +
112+
filePathData.filePathLengthBytes);
113+
114+
let offset = 0;
115+
offset += headerBuffer.write(AndroidLivesyncTool.DELETE_FILE_OPERATION.toString(), offset, PROTOCOL_OPERATION_LENGTH_SIZE);
116+
offset = headerBuffer.writeInt8(filePathData.filePathLengthSize, offset);
117+
offset += headerBuffer.write(filePathData.filePathLengthString, offset, filePathData.filePathLengthSize);
118+
headerBuffer.write(filePathData.relativeFilePath, offset, filePathData.filePathLengthBytes);
119+
const hash = crypto.createHash("md5").update(headerBuffer).digest();
120+
121+
await this.writeToSocket(headerBuffer);
122+
await this.writeToSocket(hash);
123123
}
124-
125-
public removeFiles(files: string[]) {
126-
return Promise.all(files.map(file => this.removeFile(file)));
124+
public async removeFiles(files: string[]): Promise<void> {
125+
for (const file of files) {
126+
await this.removeFile(file);
127+
}
127128
}
128129

129130
public generateOperationIdentifier(): string {
@@ -265,6 +266,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
265266
const error = this.checkConnectionStatus();
266267
if (error && rejectHandler) {
267268
rejectHandler(error);
269+
return false;
268270
}
269271

270272
if (error && !rejectHandler) {

0 commit comments

Comments
 (0)