Implement special flags for dump and reset db

This commit is contained in:
2025-07-20 11:47:11 +02:00
parent 774ac0f0ca
commit 9ecbbff6fa
3 changed files with 76 additions and 0 deletions

View File

@@ -71,3 +71,23 @@ func ResetWhereNecessary(associations map[string]FileCommandAssociation, db DB)
log.Debug("Done")
return nil
}
func ResetAllFiles(db DB) error {
log := cylogger.Default.WithPrefix("ResetAllFiles")
log.Debug("Start")
fileSnapshots, err := db.GetAllFiles()
if err != nil {
return err
}
log.Debug("Found %d files in database", len(fileSnapshots))
for _, fileSnapshot := range fileSnapshots {
log.Debug("Resetting file %q", fileSnapshot.FilePath)
err = os.WriteFile(fileSnapshot.FilePath, fileSnapshot.FileData, 0644)
if err != nil {
return err
}
log.Debug("File %q written to disk", fileSnapshot.FilePath)
}
log.Debug("Done")
return nil
}