check / check (push) Failing after 20m56s
A backup of a directory that holds the local index stored a torn copy of it, its -wal and -shm side files and vaultik.pid, all being written while they were read. The scan now treats these files as excluded, whatever the config says. Their paths come from index_path and the lock directory, with symlinks in their directories resolved the way source paths are. If index_path is itself a symlink, SQLite writes the file it points to, so that file and its side files are skipped too. pidlock now owns the lock directory and the PID file name, so the CLI and the scanner use the same path. database delete now removes the side files database.IndexFiles lists, the -journal file included. Model: opus-5-5
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package snapshot_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/spf13/afero"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/vaultik/internal/database"
|
|
"sneak.berlin/go/vaultik/internal/snapshot"
|
|
)
|
|
|
|
// A backup of the directory that holds vaultik's index and PID file
|
|
// stores neither, with no exclude pattern set, and still stores the
|
|
// files beside them. See https://git.eeqj.de/sneak/vaultik/issues/421.
|
|
func TestScanSkipsIndexAndLockFiles(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
const dataDir = "/home/user/.local/share/vaultik"
|
|
|
|
indexAndLockFiles := append(database.IndexFiles(dataDir+"/index.sqlite"),
|
|
dataDir+"/vaultik.pid")
|
|
|
|
fs := afero.NewMemMapFs()
|
|
for _, p := range append(indexAndLockFiles, dataDir+"/notes.txt") {
|
|
require.NoError(t, afero.WriteFile(fs, p, []byte("data"), 0o600))
|
|
}
|
|
|
|
db, err := database.NewTestDB()
|
|
require.NoError(t, err)
|
|
|
|
defer func() { _ = db.Close() }()
|
|
|
|
repos := database.NewRepositories(db)
|
|
|
|
scanner := snapshot.NewScanner(snapshot.ScannerConfig{
|
|
FS: fs,
|
|
ChunkSize: 64 * 1024,
|
|
Repositories: repos,
|
|
MaxBlobSize: 1024 * 1024,
|
|
CompressionLevel: 3,
|
|
AgeRecipients: []string{
|
|
"age1ql3z7hjy54pw3hyww5ayyfg7zqgvc7w3j2elw8zmrj2kg5sfn9aqmcac8p"},
|
|
IndexAndLockFiles: indexAndLockFiles,
|
|
})
|
|
require.NotNil(t, scanner)
|
|
|
|
ctx := context.Background()
|
|
createSnapshotRecord(ctx, t, repos, "test-snapshot")
|
|
|
|
result, err := scanner.Scan(ctx, "/home/user", "test-snapshot")
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, result.FilesScanned)
|
|
|
|
stored, err := repos.Files.GetByPath(ctx, dataDir+"/notes.txt")
|
|
require.NoError(t, err)
|
|
require.NotNil(t, stored, "a file beside the index is stored")
|
|
|
|
for _, p := range indexAndLockFiles {
|
|
f, err := repos.Files.GetByPath(ctx, p)
|
|
require.NoError(t, err)
|
|
require.Nil(t, f, "%s is not stored", p)
|
|
}
|
|
}
|