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

Return the real transferred files when transferDirectory of device fs is called #992

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion definitions/mobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ declare module Mobile {
putFile(localFilePath: string, deviceFilePath: string, appIdentifier: string): Promise<void>;
deleteFile?(deviceFilePath: string, appIdentifier: string): Promise<void>;
transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<void>;
transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<void>;
transferDirectory(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string): Promise<Mobile.ILocalToDevicePathData[]>;
transferFile?(localFilePath: string, deviceFilePath: string): Promise<void>;
createFileOnDevice?(deviceFilePath: string, fileContent: string): Promise<void>;
}
Expand Down
47 changes: 24 additions & 23 deletions mobile/android/android-device-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
}
}

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

await Promise.all(
localToDevicePaths.map(async localToDevicePathData => {
Expand All @@ -98,32 +98,31 @@ export class AndroidDeviceFileSystem implements Mobile.IDeviceFileSystem {
})
);

let commandsDeviceFilePath = this.$mobileHelper.buildDevicePath(await deviceAppData.getDeviceProjectRootPath(), "nativescript.commands.sh");
const commandsDeviceFilePath = this.$mobileHelper.buildDevicePath(await deviceAppData.getDeviceProjectRootPath(), "nativescript.commands.sh");

let deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
let filesToChmodOnDevice: string[] = devicePaths;
if (this.$options.force) {
let tranferredFiles: Mobile.ILocalToDevicePathData[] = [];
const oldShasums = await deviceHashService.getShasumsFromDevice();
if (this.$options.force || !oldShasums) {
await this.adb.executeShellCommand(["rm", "-rf", deviceHashService.hashFileDevicePath]);
await this.adb.executeCommand(["push", projectFilesPath, await deviceAppData.getDeviceProjectRootPath()]);
tranferredFiles = localToDevicePaths;
} else {
// Create or update file hashes on device
let oldShasums = await deviceHashService.getShasumsFromDevice();
if (oldShasums) {
let changedShasums: any = _.omitBy(currentShasums, (hash: string, pathToFile: string) => !!_.find(oldShasums, (oldHash: string, oldPath: string) => pathToFile === oldPath && hash === oldHash));
this.$logger.trace("Changed file hashes are:", changedShasums);
filesToChmodOnDevice = [];
await Promise.all(
_(changedShasums)
.map((hash: string, filePath: string) => _.find(localToDevicePaths, ldp => ldp.getLocalPath() === filePath))
.map(localToDevicePathData => {
filesToChmodOnDevice.push(`"${localToDevicePathData.getDevicePath()}"`);
return this.transferFile(localToDevicePathData.getLocalPath(), localToDevicePathData.getDevicePath());
})
.value()
);
} else {
await this.adb.executeCommand(["push", projectFilesPath, await deviceAppData.getDeviceProjectRootPath()]);
}
const changedShasums: any = _.omitBy(currentShasums, (hash: string, pathToFile: string) => !!_.find(oldShasums, (oldHash: string, oldPath: string) => pathToFile === oldPath && hash === oldHash));
this.$logger.trace("Changed file hashes are:", changedShasums);
filesToChmodOnDevice = [];
await Promise.all(
_(changedShasums)
.map((hash: string, filePath: string) => _.find(localToDevicePaths, ldp => ldp.getLocalPath() === filePath))
.map(localToDevicePathData => {
tranferredFiles.push(localToDevicePathData);
filesToChmodOnDevice.push(`"${localToDevicePathData.getDevicePath()}"`);
return this.transferFile(localToDevicePathData.getLocalPath(), localToDevicePathData.getDevicePath());
})
.value()
);
}

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

await deviceHashService.uploadHashFileToDevice(currentShasums);

return tranferredFiles;
}

public async transferFile(localPath: string, devicePath: string): Promise<void> {
Expand Down
9 changes: 8 additions & 1 deletion mobile/ios/device/ios-application-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ export class IOSApplicationManager extends ApplicationManagerBase {
}

public async stopApplication(appIdentifier: string, appName?: string): Promise<void> {
await this.$iosDeviceOperations.stop([{ deviceId: this.device.deviceInfo.identifier, ddi: this.$options.ddi, appId: appIdentifier }]);
const action = () => this.$iosDeviceOperations.stop([{ deviceId: this.device.deviceInfo.identifier, ddi: this.$options.ddi, appId: appIdentifier }]);

try {
await action();
} catch (err) {
this.$logger.trace(`Error when trying to stop application ${appIdentifier} on device ${this.device.deviceInfo.identifier}: ${err}. Retrying stop operation.`);
await action();
}
}

public async restartApplication(applicationId: string, appName?: string): Promise<void> {
Expand Down
5 changes: 3 additions & 2 deletions mobile/ios/device/ios-device-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export class IOSDeviceFileSystem implements Mobile.IDeviceFileSystem {
}]);
}

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

private async uploadFilesCore(filesToUpload: IOSDeviceLib.IUploadFilesData[]): Promise<void> {
Expand Down
5 changes: 3 additions & 2 deletions mobile/ios/simulator/ios-simulator-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export class IOSSimulatorFileSystem implements Mobile.IDeviceFileSystem {
));
}

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

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