knime://knime.workflow URLs in new file-handling

I have some legacy internal nodes which I am trying to migrate to the new filehandling code, and I am running into some issues around knime://knime.workflow/..... URIs.

My legacy code took a file path from a simple File Browser component and read that file, after a bit of work to handle file:, knime: etc protocols.

I have now a configurable node with optional File System input port, and in the node settings pane the following:

    SettingsModelReaderFileChooser configPathModel =
				createConfigFilePathModel(
						creationConfig.getPortConfig().orElseThrow());
    DialogComponentReaderFileChooser configFileDiaC =
				new DialogComponentReaderFileChooser(configPathModel,
						"MyConfigFileHistory",
						createFlowVariableModel(
								configPathModel.getKeysForFSLocation(),
								FSLocationVariableType.INSTANCE));
    addDialogComponent(configFileDiaC);

That looks to work ok for new node instances, except that if I select Relative To as the file system, and Current Workflow then I cannot actually browse any files in the workflow itself (I think this was added as a security constraint)

Now, in my NodeModel I have the following for the SettingsModel for the path to the file:

	protected final SettingsModelReaderFileChooser m_settingsFileName = smr.registerSettingsModel(
				createConfigFilePathModel(portsConfig), 2, (mdl, settings) -> {
					try {
						String oldPath =
								settings.getString(CONFIG_FILE_PATH);
						FSLocation fsLoc =
								FSLocationUtil.createFromURL(oldPath);
						mdl.setLocation(fsLoc);
					} catch (InvalidSettingsException e) {
						throw new UncheckedInvalidSettingsException(e);
					}
				});

A bit of background explanation here - smr is an instance of the Vernalis SettingsModelRegistryImpl class, which will handle new or changed models. The BiConsumer<SettingsModelReaderFileChooser, NodeSettingsRO> defined (mdl, settings) -> ... will be applied when there is no saved settings for the new model in an attempt to take the legacy settings and attempt to transfer the old settings to the new model.

Firstly - this works! (That’s great - thanks for including the really useful FSLocationUtil class here, which makes this easy!)

Except… It doesn’t actually work for paths such as knime://knime.workflow/myconfig.cfg - the path is correctly translated to Relative to and Current workflow with the actual path then myconfig.cfg, BUT, the node dialog and model during the configure phase are both 100% certain that the file (which does exist!) does not exist!

I assume this is again for the same reason as above - i.e. security of not being able to randomly dig around within the workflow folder itself. Please could someone either confirm this, or if that is not the case suggest an appropriate fix?

Thanks

Steve

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.