Skip to content

Commit

Permalink
Merge pull request #2015 from codefori/feature/fixDeployCCSID
Browse files Browse the repository at this point in the history
Set CCSID of deployed files to 1208 if needed
  • Loading branch information
sebjulliand authored Apr 30, 2024
2 parents 8c8159c + 8792874 commit 5d6b849
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/api/local/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export namespace Deployment {
export const button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
export const workspaceChanges: Map<vscode.WorkspaceFolder, Map<string, vscode.Uri>> = new Map;

let fixCCSID: boolean | undefined;

export function initialize(context: vscode.ExtensionContext) {
button.command = {
command: `code-for-ibmi.launchDeploy`,
Expand Down Expand Up @@ -89,6 +91,7 @@ export namespace Deployment {
});

instance.onEvent("disconnected", () => {
fixCCSID = undefined;
button.hide();
})
}
Expand Down Expand Up @@ -228,6 +231,17 @@ export namespace Deployment {
tar.t({ sync: true, file: localTarball.name, onentry: entry => entries.push(entry.path) });
deploymentLog.appendLine(`${entries.length} file(s) uploaded to ${parameters.remotePath}`);
entries.sort().map(e => `\t${e}`).forEach(deploymentLog.appendLine);

if (await mustFixCCSID()) {
progress?.report({ message: 'Fixing files CCSID...' });
const fix = await connection.sendCommand({ command: `${connection.remoteFeatures.setccsid} -R 1208 ${parameters.remotePath}` });
if (fix.code === 0) {
deploymentLog.appendLine(`Deployed files' CCSID set to 1208`);
}
else {
deploymentLog.appendLine(`Failed to set deployed files' CCSID to 1208: ${fix.stderr}`);
}
}
}
finally {
deploymentLog.appendLine('');
Expand All @@ -238,4 +252,20 @@ export namespace Deployment {
deploymentLog.appendLine(`${localTarball.name} deleted`);
}
}

/**
* Check if default CCSID of created/deployed files is not 1208 (utf-8).
*
* @returns `true` if the default CCSID of IFS files is not 1208.
*/
async function mustFixCCSID() {
if (fixCCSID === undefined) {
const connection = getConnection();
fixCCSID = Boolean(connection.remoteFeatures.attr) &&
Boolean(connection.remoteFeatures.setccsid) &&
(await connection.sendCommand({ command: `touch codeforiccsidtest && ${connection.remoteFeatures.attr} codeforiccsidtest CCSID && rm codeforiccsidtest` })).stdout !== "1208";
}

return fixCCSID;
}
}

0 comments on commit 5d6b849

Please sign in to comment.