fix: safe path calculation using filepath.Rel to avoid incorrect filename syntax error on Windows

This commit is contained in:
lx1056758714-glitch
2025-12-26 15:15:28 +08:00
parent 8081bf78e9
commit 5217a50c70

View File

@@ -169,7 +169,11 @@ func (s *Service) DecryptDBFile(dbFile string) error {
return err
}
output := filepath.Join(s.conf.GetWorkDir(), dbFile[len(s.conf.GetDataDir()):])
relPath, err := filepath.Rel(s.conf.GetDataDir(), dbFile)
if err != nil {
return fmt.Errorf("failed to get relative path for %s: %w", dbFile, err)
}
output := filepath.Join(s.conf.GetWorkDir(), relPath)
if err := util.PrepareDir(filepath.Dir(output)); err != nil {
return err
}