allow for dangling symlinks

Signed-off-by: Will Wang <willww64@gmail.com>
This commit is contained in:
Will Wang 2024-07-24 12:10:32 +08:00
parent 115fdd979b
commit c6d1de3397
No known key found for this signature in database
GPG Key ID: 777CB89880638858
1 changed files with 3 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
@ -167,9 +168,9 @@ func (configFile *ConfigFile) Save() (retErr error) {
return errors.Wrap(err, "error closing temp file")
}
// Handle situation where the configfile is a symlink
cfgFile := configFile.Filename
if f, err := filepath.EvalSymlinks(cfgFile); err == nil {
// Handle situations where `configFile.Filename` is a symlink, and allow for dangling symlinks
if f, err := filepath.EvalSymlinks(cfgFile); err == nil || errors.Is(err, fs.ErrNotExist) {
cfgFile = f
}