Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file extension during file source orbit rename #325

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions src/views/projectExplorer/migrateSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ComplexTab, SelectItem } from "@halcyontech/vscode-ibmi-types/api/Custo
import { IProject } from "../../iproject";
import * as path from "path";
import * as tar from "tar";
import * as fs from 'fs';

/**
* Represents the configuration for a migration.
Expand Down Expand Up @@ -158,6 +159,11 @@ export async function migrateSource(iProject: IProject, library: string): Promis
if (migrationConfig.automaticRename) {
progress.report({ message: l10n.t('Renaming file extensions to be more precise...'), increment: increment });
await commands.executeCommand('vscode-sourceorbit.autoFix', workspaceFolder, 'renames');

// Fix file extensions with the format FILE.pgm.CLLE to FILE.PGM.CLLE
if (!migrationConfig.lower) {
fixExtensions(migrationConfig.workspaceFolderUri!.fsPath);
}
}

if (migrationConfig.fixIncludes) {
Expand Down Expand Up @@ -187,6 +193,36 @@ export async function migrateSource(iProject: IProject, library: string): Promis
}
}

function fixExtensions(workspaceFolder: string): void {
const filesAndDirs = fs.readdirSync(workspaceFolder);

filesAndDirs.forEach((fileDir: string) => {
const path = `${workspaceFolder}/${fileDir}`;
const stats = fs.statSync(path);

if (stats.isDirectory()) {
fixExtensions(path);
} else {
const fileSplit = fileDir.split('.');
const extension = fileSplit.at(-1);

if (fileSplit.length === 3 && extension?.toUpperCase() === extension) {
fileSplit[1] = fileSplit[1].toUpperCase();

const newFileName = fileSplit.join('.');

fs.rename(path, workspaceFolder + "/" + newFileName, (error) => {
if (error) {
console.error(`Error fixing extension's case for file: ${fileDir}`);
} else {
console.log(`File ${fileDir} renamed successfully to ${newFileName}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really an internal issue that we didn't get the case right the first time, so I don't think we should issue a consule statement here.
In fact, couldn't this be fixed at the time we do the initial rename? won't the console log have the wrong case there?

}
});
}
}
});
}

/**
* Get the migration configuration by retrieving the source physical files
* in a library and prompting for the configuration parameters.
Expand Down
Loading