Files
Roger a7741eaab2 refactor: name dirs by what they hold, trim exports (#692)
Bare dir now always means a user data dir, so the snapshot root, the export listing, and the
keys.json kind get their own words; names used only inside their package are no longer exported.
2026-11-10 17:00:43 +08:00

32 lines
653 B
Go

package snapshot
import (
"fmt"
"io/fs"
"path/filepath"
"github.com/moond4rk/hackbrowserdata/internal/zipfile"
)
func (r *Root) Zip(archivePath string) error {
var names []string
walkErr := filepath.WalkDir(r.path, func(walkedPath string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
if entry.IsDir() {
return nil
}
relativePath, err := filepath.Rel(r.path, walkedPath)
if err != nil {
return err
}
names = append(names, filepath.ToSlash(relativePath))
return nil
})
if walkErr != nil {
return fmt.Errorf("zip %s: %w", r.path, walkErr)
}
return zipfile.Write(archivePath, r.path, names)
}