feat: add update config

main
Tran Hau 2021-01-18 15:32:25 +07:00
parent dae2c42252
commit bbb84fe09f
1 changed files with 22 additions and 0 deletions

View File

@ -86,6 +86,28 @@ func (c *Config) Install() error {
// external -> internal
func (c *Config) Update() error {
for _, app := range c.Apps {
for _, file := range app.Files {
if err := os.RemoveAll(file.Internal); err != nil {
return fmt.Errorf("failed to remove %s: %w", file.Internal, err)
}
if err := copy.CopyFile(file.External, file.Internal); err != nil {
return fmt.Errorf("failed to copy from %s to %s: %w", file.External, file.Internal, err)
}
}
for _, dir := range app.Dirs {
if err := os.RemoveAll(dir.Internal); err != nil {
return fmt.Errorf("failed to remove %s: %w", dir.Internal, err)
}
if err := copy.CopyDir(dir.External, dir.Internal); err != nil {
return fmt.Errorf("failed to copy from %s to %s: %w", dir.External, dir.Internal, err)
}
}
}
return nil
}