github-actions[bot] commented on issue #18636:
URL: 
https://github.com/apache/dolphinscheduler/issues/18636#issuecomment-5658255434

   ### Search before asking
   
   - [x] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar issues.
   
   ### What happened
   
   When the resource center contains two directories where one directory name 
is a prefix of the other (e.g. `datax_to_doris` and `datax_to_doris2`), 
selecting a file inside the longer-named directory fails validation:
   
   ```
   未授权或已删除资源: 
datax_to_doris2/bcwl_cnzs_pservice_qualityassignmentexecutiondetail_df.json;
   ```
   
   The file is listed and selectable in the resource dropdown, but as soon as 
it is selected (and again when the workflow is saved/reopened), the UI reports 
it as unauthorized or deleted. The actual workflow run then fails with a 
file-not-found error, because the resource reference never really validated.
   
   The resource itself exists and is readable — this is a frontend validation 
bug, not a deleted/unauthorized resource.
   
   ### What you expected to happen
   
   Selecting an existing resource file should pass validation, and the workflow 
should be able to reference it, regardless of whether another directory in the 
tree shares a name prefix with its parent.
   
   The bug is in 
`dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-resources.ts`.
 The `isDirectory` helper decides whether the current candidate is the ancestor 
directory of `fullName` by matching
   
   ```ts
   res.dirctory && new RegExp(`^${res.fullName}`).test(fullName)
   ```
   
   The regex has no path-boundary anchor, so `^/resources/datax_to_doris` also 
matches `/resources/datax_to_doris2/foo.json`. Because the loop returns on the 
first directory that matches, it descends into the wrong sibling directory, 
never finds the file, and falls through to `addResourceNode(...)` + `return 
false`, which is what produces the "unauthorized or deleted resource" message.
   
   Directories without such a prefix relationship work fine, which is why the 
problem appears specific to certain names.
   
   ### How to reproduce
   
   1. In the resource center, create two directories where one name is a prefix 
of the other, e.g. `datax_to_doris` and `datax_to_doris2`.
   2. Upload a file into `datax_to_doris2`.
   3. Create/edit a workflow, add a task node that takes a resource file (e.g. 
Shell/Python).
   4. Open the resource dropdown and select the file inside `datax_to_doris2`.
   5. The UI reports `未授权或已删除资源: datax_to_doris2/<file>`.
   
   The same happens if the two directory names differ only by a suffix 
(`datax_to_doris_v2` also collides, since it still starts with 
`datax_to_doris`).
   
   Workaround: rename the longer directory so it does not start with the 
shorter directory name (e.g. `datax2_to_doris`), then re-select the file.
   
   ### Anything else
   
   Occurs every time when the prefix relationship exists; never when it does 
not.
   
   Proposed fix — anchor the prefix to a path boundary:
   
   ```ts
   res.dirctory && new RegExp(`^${res.fullName}(/|$)`).test(fullName)
   ```
   
   Confirmed present unchanged on the current `dev` branch, and reproduced 
independently.
   
   ### Version
   
   3.4.2
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   
   ---
   中文补充:资源中心里若存在两个目录名互为前缀(如 `datax_to_doris` 与 
`datax_to_doris2`),选择后者目录内的文件时会报「未授权或已删除资源」,任务执行时也找不到文件。根因是 `use-resources.ts` 
的 `isDirectory` 用了 `^${fullName}` 做前缀判断,缺少路径分隔符边界,导致递归先走进短名目录。改为 
`^${fullName}(/|$)` 即可。绕开办法是把目录改成不以短名开头。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to