Files
HackBrowserData/filemanager/session.go
T
Roger 0b8cc23216 refactor: introduce internal/snapshot for copy and zip (#653)
One copier and one zip transport serve archive, restore, and every profile copy, so locked-file handling has one home.
Dropping otiai10/copy takes x/sync out of every binary and testing out of the Windows exe.
2026-10-27 14:54:54 +08:00

40 lines
1.0 KiB
Go

package filemanager
import (
"fmt"
"os"
"github.com/moond4rk/hackbrowserdata/internal/snapshot"
)
// Session manages temporary files for a single browser extraction run.
// It creates an isolated temp directory and provides methods to copy
// browser files into it. Call Cleanup() when done to remove all temp files.
type Session struct {
tempDir string
}
// NewSession creates a session with a unique temporary directory.
func NewSession() (*Session, error) {
dir, err := os.MkdirTemp("", "hbd-*")
if err != nil {
return nil, fmt.Errorf("create temp dir: %w", err)
}
return &Session{tempDir: dir}, nil
}
// TempDir returns the session's temporary directory path.
func (s *Session) TempDir() string {
return s.tempDir
}
// Acquire copies a browser file (or directory) from src to dst with the snapshot copier.
func (s *Session) Acquire(src, dst string, isDir bool) error {
return snapshot.Copy(src, dst, isDir)
}
// Cleanup removes the session's temporary directory and all its contents.
func (s *Session) Cleanup() {
os.RemoveAll(s.tempDir)
}