Skip to content

Commit

Permalink
fix(ds): update rename to match FS sample; check editor before rename
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Nov 18, 2024
1 parent 7143336 commit d728271
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
const ds = isPdsMember ? items.find((it) => it.member === entry.name) : items?.[0];
if (ds != null && "m4date" in ds) {
const { m4date, mtime, msec }: { m4date: string; mtime: string; msec: string } = ds;
const newTime = dayjs(`${m4date} ${mtime}:${msec}`).unix();
const newTime = dayjs(`${m4date} ${mtime}:${msec}`).valueOf();
if (entry.mtime != newTime) {
entry.mtime = newTime;
// if the modification time has changed, invalidate the previous contents to signal to `readFile` that data needs to be fetched
entry.wasAccessed = false;
}
return { ...entry, mtime: newTime };
}
}

Expand Down Expand Up @@ -687,7 +687,8 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
}

const entry = this.lookup(oldUri, false) as PdsEntry | DsEntry;
const parentDir = this._lookupParentDirectory(oldUri);
const oldParent = this._lookupParentDirectory(oldUri);
const newParent = this._lookupParentDirectory(newUri);

const oldName = entry.name;
const newName = path.posix.basename(newUri.path);
Expand Down Expand Up @@ -721,14 +722,14 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
throw err;
}

parentDir.entries.delete(entry.name);
oldParent.entries.delete(entry.name);
entry.name = newName;

// Build the new path using the previous path and new file/folder name.
const newPath = path.posix.join(entry.metadata.path, "..", newName);

entry.metadata.path = newPath;
parentDir.entries.set(newName, entry);
newParent.entries.set(newName, entry);

if (FsDatasetsUtils.isPdsEntry(entry)) {
for (const [_, member] of entry.entries) {
Expand Down
22 changes: 22 additions & 0 deletions packages/zowe-explorer/src/trees/dataset/DatasetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,29 @@ export class DatasetTree extends ZoweTreeProvider<IZoweDatasetTreeNode> implemen
*/
public async rename(node: IZoweDatasetTreeNode): Promise<void> {
ZoweLogger.trace("DatasetTree.rename called.");
const currentFilePath = node.resourceUri.path; // The user's complete local file path for the node
await Profiles.getInstance().checkCurrentProfile(node.getProfile());
const openedTextDocuments: readonly vscode.TextDocument[] = vscode.workspace.textDocuments; // Array of all documents open in VS Code

for (const doc of openedTextDocuments) {
const docIsChild = SharedUtils.checkIfChildPath(currentFilePath, doc.fileName);
if (doc.fileName === currentFilePath || docIsChild === true) {
if (doc.isDirty === true) {
Gui.errorMessage(
vscode.l10n.t({
message:
"Unable to rename {0} because you have unsaved changes in this data set. " +
"Please save your work before renaming the data set.",
args: [node.label],
comment: ["Node path"],
}),
{ vsCodeOpts: { modal: true } }
);
return;
}
}
}

if (Profiles.getInstance().validProfile === Validation.ValidationType.VALID || !SharedContext.isValidationEnabled(node)) {
return SharedContext.isDsMember(node) ? this.renameDataSetMember(node) : this.renameDataSet(node);
}
Expand Down

0 comments on commit d728271

Please sign in to comment.