Skip to content

Commit

Permalink
Merge pull request #1768 from codefori/fix/pathSplit
Browse files Browse the repository at this point in the history
Fix path splitting when opening a member on an IASP
  • Loading branch information
sebjulliand committed Jan 8, 2024
2 parents 88120f9 + e6dec61 commit 715fa99
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import fs from 'fs';
import path from 'path';
import tmp from 'tmp';
import util from 'util';
import { window } from 'vscode';
import { ObjectTypes } from '../filesystems/qsys/Objects';
import { CommandResult, IBMiError, IBMiFile, IBMiMember, IBMiObject, IFSFile, QsysPath } from '../typings';
import { ConnectionConfiguration } from './Configuration';
import { default as IBMi } from './IBMi';
import { Tools } from './Tools';
import { window } from 'vscode';
const tmpFile = util.promisify(tmp.file);
const readFileAsync = util.promisify(fs.readFile);
const writeFileAsync = util.promisify(fs.writeFile);
Expand Down Expand Up @@ -861,9 +861,9 @@ export default class IBMiContent {
if (path.startsWith('/')) { //IFS path
return this.config.protectedPaths.some(p => path.startsWith(p));
}
else { //QSYS path
const [library] = path.split('/');
return this.config.protectedPaths.includes(library.toLocaleUpperCase());
else { //QSYS path
const qsysObject = Tools.parseQSysPath(path);
return this.config.protectedPaths.includes(qsysObject.library.toLocaleUpperCase());
}
}
}
19 changes: 18 additions & 1 deletion src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Crypto from 'crypto';
import { readFileSync } from "fs";
import path from "path";
import vscode from "vscode";
import { IBMiMessage, IBMiMessages } from '../typings';
import { IBMiMessage, IBMiMessages, QsysPath } from '../typings';
import { API, GitExtension } from "./import/git";

export namespace Tools {
Expand Down Expand Up @@ -235,4 +235,21 @@ export namespace Tools {
findId: id => messages.find(m => m.id === id)
}
}

export function parseQSysPath(path: string) : QsysPath{
const parts = path.split('/');
if(parts.length > 3){
return {
asp: parts[0],
library: parts[1],
name: parts[2]
}
}
else{
return {
library: parts[0],
name: parts[1]
}
}
}
}
34 changes: 17 additions & 17 deletions src/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
options.readonly = !await instance.getContent()?.testStreamFile(path, "w");
}
else {
const [library, name] = path.split('/');
const writable = await instance.getContent()?.checkObject({ library, name, type: '*FILE' }, "*UPD");
const qsysObject = Tools.parseQSysPath(path);
const writable = await instance.getContent()?.checkObject({ library: qsysObject.library, name: qsysObject.name, type: '*FILE' }, "*UPD");
if (!writable) {
options.readonly = true;
}
Expand Down Expand Up @@ -707,19 +707,19 @@ async function createQuickPickItemsList(
labelFiltered: string = ``, filtered: vscode.QuickPickItem[] = [],
labelRecent: string = ``, recent: vscode.QuickPickItem[] = [],
labelCached: string = ``, cached: vscode.QuickPickItem[] = [],
) {
const clearRecentArray = [{ label: ``, kind: vscode.QuickPickItemKind.Separator }, { label: CLEAR_RECENT }];
const clearCachedArray = [{ label: ``, kind: vscode.QuickPickItemKind.Separator }, { label: CLEAR_CACHED }];

const returnedList: vscode.QuickPickItem[] = [
{ label: labelFiltered, kind: vscode.QuickPickItemKind.Separator },
...filtered,
{ label: labelRecent, kind: vscode.QuickPickItemKind.Separator },
...recent,
...(recent.length != 0 ? clearRecentArray : []),
{ label: labelCached, kind: vscode.QuickPickItemKind.Separator },
...cached,
...(cached.length != 0 ? clearCachedArray : [])
];
return returnedList;
) {
const clearRecentArray = [{ label: ``, kind: vscode.QuickPickItemKind.Separator }, { label: CLEAR_RECENT }];
const clearCachedArray = [{ label: ``, kind: vscode.QuickPickItemKind.Separator }, { label: CLEAR_CACHED }];

const returnedList: vscode.QuickPickItem[] = [
{ label: labelFiltered, kind: vscode.QuickPickItemKind.Separator },
...filtered,
{ label: labelRecent, kind: vscode.QuickPickItemKind.Separator },
...recent,
...(recent.length != 0 ? clearRecentArray : []),
{ label: labelCached, kind: vscode.QuickPickItemKind.Separator },
...cached,
...(cached.length != 0 ? clearCachedArray : [])
];
return returnedList;
}

0 comments on commit 715fa99

Please sign in to comment.