Implement proper "reset" that reads snapshots from database
This commit is contained in:
@@ -33,3 +33,41 @@ func ToAbs(path string) string {
|
||||
log.Trace("Cwd: %q", cwd)
|
||||
return CleanPath(filepath.Join(cwd, path))
|
||||
}
|
||||
|
||||
func ResetWhereNecessary(associations map[string]FileCommandAssociation, db DB) error {
|
||||
log := cylogger.Default.WithPrefix("ResetWhereNecessary")
|
||||
log.Debug("Start")
|
||||
dirtyFiles := make(map[string]struct{})
|
||||
for _, association := range associations {
|
||||
for _, command := range association.Commands {
|
||||
log.Debug("Checking command %q for file %q", command.Name, association.File)
|
||||
if command.Reset {
|
||||
log.Debug("Command %q requires reset for file %q", command.Name, association.File)
|
||||
dirtyFiles[association.File] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, command := range association.IsolateCommands {
|
||||
log.Debug("Checking isolate command %q for file %q", command.Name, association.File)
|
||||
if command.Reset {
|
||||
log.Debug("Isolate command %q requires reset for file %q", command.Name, association.File)
|
||||
dirtyFiles[association.File] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Debug("Dirty files: %v", dirtyFiles)
|
||||
for file := range dirtyFiles {
|
||||
log.Debug("Resetting file %q", file)
|
||||
fileData, err := db.GetFile(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug("Writing file %q to disk", file)
|
||||
err = os.WriteFile(file, fileData, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug("File %q written to disk", file)
|
||||
}
|
||||
log.Debug("Done")
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user