@@ -39,18 +39,23 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
39
39
return `${ LiveSyncPaths . ANDROID_TMP_DIR_NAME } /${ appIdentifier } -livesync-in-progress` ;
40
40
}
41
41
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
+ }
44
49
}
45
50
46
- private async doSync ( liveSyncInfo : ILiveSyncResultInfo , { doRefresh = false } : { doRefresh ?: boolean } = { } ) : Promise < IAndroidLivesyncSyncOperationResult > {
51
+ private async doSync ( liveSyncInfo : ILiveSyncResultInfo , projectData : IProjectData ) : Promise < IAndroidLivesyncSyncOperationResult > {
47
52
const operationId = this . livesyncTool . generateOperationIdentifier ( ) ;
48
53
49
54
let result = { operationId, didRefresh : true } ;
50
55
51
56
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 ) ;
54
59
55
60
const syncInterval : NodeJS . Timer = setInterval ( ( ) => {
56
61
if ( this . livesyncTool . isOperationInProgress ( operationId ) ) {
@@ -64,30 +69,29 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
64
69
} ;
65
70
66
71
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 ) ) ;
68
75
69
76
result = await doSyncPromise ;
77
+ } else {
78
+ await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
70
79
}
71
80
72
- await this . device . fileSystem . deleteFile ( this . getPathToLiveSyncFileOnDevice ( liveSyncInfo . deviceAppData . appIdentifier ) , liveSyncInfo . deviceAppData . appIdentifier ) ;
73
-
74
81
return result ;
75
82
}
76
83
77
- public async refreshApplication ( projectData : IProjectData , liveSyncInfo : ILiveSyncResultInfo ) {
84
+ public async refreshApplication ( projectData : IProjectData , liveSyncInfo : IAndroidLiveSyncResultInfo ) {
78
85
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 ) {
85
87
await this . device . applicationManager . restartApplication ( { appId : liveSyncInfo . deviceAppData . appIdentifier , projectName : projectData . projectName } ) ;
86
88
}
87
89
}
88
90
89
91
public async removeFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] , projectFilesPath : string ) : Promise < void > {
90
92
await this . livesyncTool . removeFiles ( _ . map ( localToDevicePaths , ( element : any ) => element . filePath ) ) ;
93
+
94
+ await this . getDeviceHashService ( deviceAppData . appIdentifier ) . removeHashes ( localToDevicePaths ) ;
91
95
}
92
96
93
97
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
96
100
if ( isFullSync ) {
97
101
transferredFiles = await this . _transferDirectory ( deviceAppData , localToDevicePaths , projectFilesPath ) ;
98
102
} else {
99
- transferredFiles = await this . _transferFiles ( localToDevicePaths ) ;
103
+ transferredFiles = await this . _transferFiles ( deviceAppData , localToDevicePaths ) ;
100
104
}
101
105
102
106
return transferredFiles ;
103
107
}
104
108
105
- private async _transferFiles ( localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
109
+ private async _transferFiles ( deviceAppData : Mobile . IDeviceAppData , localToDevicePaths : Mobile . ILocalToDevicePathData [ ] ) : Promise < Mobile . ILocalToDevicePathData [ ] > {
106
110
await this . livesyncTool . sendFiles ( localToDevicePaths . map ( localToDevicePathData => localToDevicePathData . getLocalPath ( ) ) ) ;
107
111
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
+
108
118
return localToDevicePaths ;
109
119
}
110
120
0 commit comments