Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mathstuf
Copy link
Contributor

What is the purpose of this change?

Support config files living at locations found by multiple symlink hops.

Was the change discussed in an issue or in the forum before?

No.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

As an example, if the following symlinks exist:

- `configfile` -> `intermediate`
- `intermediate` -> `trampoline`
- `trampoline` -> `actual_file`

`rclone --config configfile config` would rewrite the `intermediate`
path as a real file, breaking the symlink chain. Instead, chase all
symlinks and rewrite `actual_file`.
@mathstuf mathstuf force-pushed the multiple-symlink-resolution branch from 267ca9b to e6fbdcb Compare August 12, 2025 18:58
Copy link
Member

@ncw ncw left a comment

Choose a reason for hiding this comment

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

This is a nice idea.

What about using filepath.EvalSymlinks that should simplify the logic?

@mathstuf
Copy link
Contributor Author

Ah, that does look a lot simpler. I'll try that out. I'll also add a test for a broken symlink.

@mathstuf
Copy link
Contributor Author

That breaks a lot of tests…

Since the symlink resolution is now step-by-step (see parent commit),
symlink loops must now be manually detected. Keep track of visited paths
and error if we come across a path a second time.
@mathstuf
Copy link
Contributor Author

I tried to use the filepath.EvalSymlinks API but that ends up breaking other tests. If the simplification is wanted, I think it needs a separate PR to also consider the behavior change(s) covered by other tests expecting specific errors.

@mathstuf mathstuf force-pushed the multiple-symlink-resolution branch 2 times, most recently from 1d2fe85 to 802eabd Compare August 14, 2025 00:48
@mathstuf mathstuf force-pushed the multiple-symlink-resolution branch from 802eabd to aa4224c Compare August 14, 2025 01:28
@ncw
Copy link
Member

ncw commented Aug 15, 2025

I tried to use the filepath.EvalSymlinks API but that ends up breaking other tests. If the simplification is wanted, I think it needs a separate PR to also consider the behavior change(s) covered by other tests expecting specific errors.

I would prefer to use filepath.EvalSymlinks if possible as following symlinks properly is non trivial so I'd rather get the standard library to do it for us.

@mathstuf
Copy link
Contributor Author

I think that loses error reporting fidelity as most of the configfile test failure modes start reporting different error codes. But if that is acceptable, I can push harder on that API call.

@ncw
Copy link
Member

ncw commented Aug 16, 2025

@mathstuf start pulling on that thread and see what unravels - we can review after.

@mathstuf
Copy link
Contributor Author

mathstuf commented Sep 2, 2025

I don't think it's going to work out. I believe the issue is that if the file doesn't exist, we get no information about any intermediate path resolution in the meantime. We would have to evalSymlinks on each path component until we get a non-no-exist error and then paste back the path components stripped on the way there to get the absolute path where the configuration file would exist if the intermediate directory components existed (as normal directories) and the file config file name (as a normal file). I don't think it would be any simpler than the existing logic and almost certainly more expensive (due to repeated EvalSymlinks calls each starting from scratch rather than chasing from what we know we have and stopping when things fall apart).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants