Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 09330ac

Browse files
Return the real transferred files when transferDirectory of device fs is called
When uploading files on devices/emulators, we are executing either `transferDirectory` or `transferFiles` methods of the specific device instance. However for Android devices, the transferDirectory method has some logic to transfer only modified files (based on shasums from previous execution). So it doesn't really transfer the directory, but just several files. For LiveSync purposes it is important to know which are the tranferred files, so change the return type of `transferDirectory` method to return the exact files that we've sent to device.
1 parent 0ff4e5d commit 09330ac

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

definitions/mobile.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ declare module Mobile {
296296
putFile(localFilePath: string, deviceFilePath: string, appIdentifier: string): Promise<void>;
297297
deleteFile?(deviceFilePath: string, appIdentifier: string): Promise<void>;
298298
transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void>;
299-
transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void>;
299+
transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]>;
300300
transferFile?(localFilePath: string, deviceFilePath: string): Promise<void>;
301301
createFileOnDevice?(deviceFilePath: string, fileContent: string): Promise<void>;
302302
}

mobile/android/android-device-file-system.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
8181
}
8282
}
8383

84-
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
84+
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
8585
let devicePaths: string[] = [],
8686
currentShasums: IStringDictionary = {};
8787

@@ -102,28 +102,27 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
102102

103103
let deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
104104
let filesToChmodOnDevice: string[] = devicePaths;
105-
if (this.$options.force) {
105+
let tranferredFiles: Mobile.ILocalToDevicePathData[] = [];
106+
let oldShasums = await deviceHashService.getShasumsFromDevice();
107+
if (this.$options.force || !oldShasums) {
106108
await this.adb.executeShellCommand(["rm", "-rf", deviceHashService.hashFileDevicePath]);
107109
await this.adb.executeCommand(["push", projectFilesPath, await deviceAppData.getDeviceProjectRootPath()]);
110+
tranferredFiles = localToDevicePaths;
108111
} else {
109112
// Create or update file hashes on device
110-
let oldShasums = await deviceHashService.getShasumsFromDevice();
111-
if (oldShasums) {
112-
let changedShasums: any = _.omitBy(currentShasums, (hash: string, pathToFile: string) => !!_.find(oldShasums, (oldHash: string, oldPath: string) => pathToFile === oldPath && hash === oldHash));
113-
this.$logger.trace("Changed file hashes are:", changedShasums);
114-
filesToChmodOnDevice = [];
115-
await Promise.all(
116-
_(changedShasums)
117-
.map((hash: string, filePath: string) => _.find(localToDevicePaths, ldp => ldp.getLocalPath() === filePath))
118-
.map(localToDevicePathData => {
119-
filesToChmodOnDevice.push(`"${localToDevicePathData.getDevicePath()}"`);
120-
return this.transferFile(localToDevicePathData.getLocalPath(), localToDevicePathData.getDevicePath());
121-
})
122-
.value()
123-
);
124-
} else {
125-
await this.adb.executeCommand(["push", projectFilesPath, await deviceAppData.getDeviceProjectRootPath()]);
126-
}
113+
let changedShasums: any = _.omitBy(currentShasums, (hash: string, pathToFile: string) => !!_.find(oldShasums, (oldHash: string, oldPath: string) => pathToFile === oldPath && hash === oldHash));
114+
this.$logger.trace("Changed file hashes are:", changedShasums);
115+
filesToChmodOnDevice = [];
116+
await Promise.all(
117+
_(changedShasums)
118+
.map((hash: string, filePath: string) => _.find(localToDevicePaths, ldp => ldp.getLocalPath() === filePath))
119+
.map(localToDevicePathData => {
120+
tranferredFiles.push(localToDevicePathData);
121+
filesToChmodOnDevice.push(`"${localToDevicePathData.getDevicePath()}"`);
122+
return this.transferFile(localToDevicePathData.getLocalPath(), localToDevicePathData.getDevicePath());
123+
})
124+
.value()
125+
);
127126
}
128127

129128
if (filesToChmodOnDevice.length) {
@@ -132,6 +131,8 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
132131
}
133132

134133
await deviceHashService.uploadHashFileToDevice(currentShasums);
134+
135+
return tranferredFiles;
135136
}
136137

137138
public async transferFile(localPath: string, devicePath: string): Promise<void> {

mobile/ios/device/ios-device-file-system.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ export class IOSDeviceFileSystem implements Mobile.IDeviceFileSystem {
6161
}]);
6262
}
6363

64-
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
65-
return this.transferFiles(deviceAppData, localToDevicePaths);
64+
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
65+
await this.transferFiles(deviceAppData, localToDevicePaths);
66+
return localToDevicePaths;
6667
}
6768

6869
private async uploadFilesCore(filesToUpload: IOSDeviceLib.IUploadFilesData[]): Promise<void> {

mobile/ios/simulator/ios-simulator-file-system.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ export class IOSSimulatorFileSystem implements Mobile.IDeviceFileSystem {
3030
));
3131
}
3232

33-
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void> {
33+
public async transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]> {
3434
let destinationPath = await deviceAppData.getDeviceProjectRootPath();
3535
this.$logger.trace(`Transferring from ${projectFilesPath} to ${destinationPath}`);
3636
let sourcePath = path.join(projectFilesPath, "*");
37-
return shelljs.cp("-Rf", sourcePath, destinationPath);
37+
shelljs.cp("-Rf", sourcePath, destinationPath);
38+
return localToDevicePaths;
3839
}
3940

4041
public async transferFile(localFilePath: string, deviceFilePath: string): Promise<void> {

0 commit comments

Comments
 (0)