backup: Keep path of stored & hashed backup files in a own $hash.path file

Since full escaped backup paths can become longer than the maximum filename size
and hashed filenames cannot be restored it is helpful to have a lookup file for
the user to resolve the hashed path.
This commit is contained in:
Jöran Karl
2025-09-19 19:56:02 +02:00
parent 1ce2202d9a
commit 02611f4ad2
4 changed files with 54 additions and 23 deletions

View File

@@ -39,8 +39,20 @@ func (b *Buffer) Serialize() error {
return err
}
name := util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath)
return util.SafeWrite(name, buf.Bytes(), true)
name, resolveName := util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath)
err = util.SafeWrite(name, buf.Bytes(), true)
if err != nil {
return err
}
if resolveName != "" {
err = util.SafeWrite(resolveName, []byte(b.AbsPath), true)
if err != nil {
return err
}
}
return nil
}
// Unserialize loads the buffer info from config.ConfigDir/buffers
@@ -50,7 +62,8 @@ func (b *Buffer) Unserialize() error {
if b.Path == "" {
return nil
}
file, err := os.Open(util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath))
name, _ := util.DetermineEscapePath(filepath.Join(config.ConfigDir, "buffers"), b.AbsPath)
file, err := os.Open(name)
if err == nil {
defer file.Close()
var buffer SerializedBuffer