@@ -39,18 +39,23 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
3939 return `${ LiveSyncPaths . ANDROID_TMP_DIR_NAME } /${ appIdentifier } -livesync-in-progress` ;
4040 }
4141
42- public async finalizeSync ( liveSyncInfo : ILiveSyncResultInfo ) {
43- await this . doSync ( liveSyncInfo ) ;
42+ public async finalizeSync ( liveSyncInfo : ILiveSyncResultInfo , projectData : IProjectData ) : Promise < IAndroidLivesyncSyncOperationResult > {
43+ try {
44+ const result = await this . doSync ( liveSyncInfo , projectData ) ;
45+ return result ;
46+ } finally {
47+ this . livesyncTool . end ( ) ;
48+ }
4449 }
4550
46- private async doSync ( liveSyncInfo : ILiveSyncResultInfo , { doRefresh = false } : { doRefresh ?: boolean } = { } ) : Promise < IAndroidLivesyncSyncOperationResult > {
51+ private async doSync ( liveSyncInfo : ILiveSyncResultInfo , projectData : IProjectData ) : Promise < IAndroidLivesyncSyncOperationResult > {
4752 const operationId = this . livesyncTool . generateOperationIdentifier ( ) ;
4853
4954 let result = { operationId, didRefresh : true } ;
5055
5156 if ( liveSyncInfo . modifiedFilesData . length ) {
52-
53- const doSyncPromise = this . livesyncTool . sendDoSyncOperation ( doRefresh , null , operationId ) ;
57+ const canExecuteFastSync = ! liveSyncInfo . isFullSync && this . canExecuteFastSyncForPaths ( liveSyncInfo . modifiedFilesData , projectData , this . device . deviceInfo . platform ) ;
58+ const doSyncPromise = this . livesyncTool . sendDoSyncOperation ( canExecuteFastSync , null , operationId ) ;
5459
5560 const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
5661 if ( this . livesyncTool . isOperationInProgress ( operationId ) ) {
@@ -64,30 +69,29 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
6469 } ;
6570
6671 this . $processService . attachToProcessExitSignals ( this , actionOnEnd ) ;
67- doSyncPromise . then ( actionOnEnd , actionOnEnd ) ;
72+ // We need to clear resources when the action fails
73+ // But we also need the real result of the action.
74+ await doSyncPromise . then ( actionOnEnd . bind ( this ) , actionOnEnd . bind ( this ) ) ;
6875
6976 result = await doSyncPromise ;
77+ } else {
78+ await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
7079 }
7180
72- await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
73-
7481 return result ;
7582 }
7683
77- public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) {
84+ public async refreshApplication ( projectData : IProjectData , liveSyncInfo : IAndroidLiveSyncResultInfo ) {
7885 const canExecuteFastSync = ! liveSyncInfo . isFullSync && this . canExecuteFastSyncForPaths ( liveSyncInfo . modifiedFilesData , projectData , this . device . deviceInfo . platform ) ;
79-
80- const syncOperationResult = await this . doSync ( liveSyncInfo , { doRefresh : canExecuteFastSync } ) ;
81-
82- this . livesyncTool . end ( ) ;
83-
84- if ( ! canExecuteFastSync || ! syncOperationResult . didRefresh ) {
86+ if ( ! canExecuteFastSync || ! liveSyncInfo . didRefresh ) {
8587 await this . device . applicationManager . restartApplication ( { appId : liveSyncInfo . deviceAppData . appIdentifier , projectName : projectData . projectName } ) ;
8688 }
8789 }
8890
8991 public async removeFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < void > {
9092 await this . livesyncTool . removeFiles ( _ . map ( localToDevicePaths , ( element : any ) => element . filePath ) ) ;
93+
94+ await this . getDeviceHashService ( deviceAppData . appIdentifier ) . removeHashes ( localToDevicePaths ) ;
9195 }
9296
9397 public async transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string , isFullSync : boolean ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
@@ -96,15 +100,21 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
96100 if ( isFullSync ) {
97101 transferredFiles = await this . _transferDirectory ( deviceAppData , localToDevicePaths , projectFilesPath ) ;
98102 } else {
99- transferredFiles = await this . _transferFiles ( localToDevicePaths ) ;
103+ transferredFiles = await this . _transferFiles ( deviceAppData , localToDevicePaths ) ;
100104 }
101105
102106 return transferredFiles ;
103107 }
104108
105- private async _transferFiles ( localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
109+ private async _transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
106110 await this . livesyncTool . sendFiles ( localToDevicePaths . map ( localToDevicePathData => localToDevicePathData . getLocalPath ( ) ) ) ;
107111
112+ // Update hashes
113+ const deviceHashService = this . getDeviceHashService ( deviceAppData . appIdentifier ) ;
114+ if ( ! await deviceHashService . updateHashes ( localToDevicePaths ) ) {
115+ this . $logger . trace ( "Unable to find hash file on device. The next livesync command will create it." ) ;
116+ }
117+
108118 return localToDevicePaths ;
109119 }
110120
0 commit comments