home: add todo

This commit is contained in:
Stanislav Chzhen 2025-10-17 09:13:37 +03:00
parent 6dc5635a7e
commit fe67680f7b
2 changed files with 13 additions and 8 deletions

View File

@ -592,16 +592,17 @@ var config = &configuration{
// configFilePath returns the absolute, symlink-resolved path to the current
// configuration file. l must not be nil.
//
// TODO(s.chzhen): Fix the bug where the wrong file may be resolved:
// [filepath.EvalSymlinks] resolves a relative path against the current working
// directory, not workDir. Make the path absolute relative to workDir before
// calling EvalSymlinks.
func configFilePath(
ctx context.Context,
l *slog.Logger,
workDir string,
confPath string,
) (resolved string) {
if !filepath.IsAbs(confPath) {
confPath = filepath.Join(workDir, confPath)
}
resolved, err := filepath.EvalSymlinks(confPath)
if err != nil {
l.DebugContext(
@ -611,7 +612,11 @@ func configFilePath(
slogutil.KeyError, err,
)
return confPath
resolved = confPath
}
if !filepath.IsAbs(confPath) {
resolved = filepath.Join(workDir, confPath)
}
return resolved

View File

@ -59,17 +59,17 @@ func TestConfigFilePath(t *testing.T) {
name: "symlink",
chDir: "",
confPath: linkConf,
want: targetPath,
want: linkPath,
}, {
name: "symlink_broken",
chDir: "",
confPath: brokenLinkConf,
want: brokenLinkPath,
}, {
name: "symlink_after_abs",
name: "symlink_before_join",
chDir: otherDir,
confPath: linkConf,
want: targetPath,
want: linkPath,
}}
for _, tc := range testCases {