Skip to content

Commit

Permalink
Add finalize install to save installed file list
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Aug 4, 2019
1 parent 17a8bde commit a706c60
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/dots/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ var installCmd = cobra.Command{

config := installer.InstallConfig{
SourceConfig: sourceConfig,
SourceLockfile: sourceLockfile,
ForceReinstall: forceReInstall,
}

installer.InstallDotfiles(prepared, config)
installed := installer.InstallDotfiles(prepared, config)
installer.RunInstallScripts(prepared, config)
installer.FinalizeInstall(installed, config)

// TODO Needs some error handling clenaup

return nil
},
Expand Down
28 changes: 27 additions & 1 deletion installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const directoryMode = 0755
// InstallConfig represents configuration options available for installing
// a single or set of dotfiles.
type InstallConfig struct {
SourceConfig *config.SourceConfig
SourceConfig *config.SourceConfig
SourceLockfile *config.SourceLockfile

// OverrideInstallPath specifies a path to install the dotfile at,
// overriding the configuration in the SourceConfig.
Expand All @@ -45,6 +46,11 @@ type InstalledDotfile struct {
// and will perform all the necessary actions to install the file into it's
// target location.
func InstallDotfile(dotfile *PreparedDotfile, config InstallConfig) error {
// Skip dotfiles that we failed to preapre
if dotfile.PrepareError != nil {
return nil
}

installPath := config.SourceConfig.InstallPath + separator + dotfile.Path

if config.OverrideInstallPath != "" {
Expand Down Expand Up @@ -125,3 +131,23 @@ func InstallDotfiles(install PreparedInstall, config InstallConfig) []*Installed

return installed
}

// FinalizeInstall writes the updated lockfile after installation
func FinalizeInstall(installed []*InstalledDotfile, installConfig InstallConfig) {
installedFiles := make([]string, 0, len(installed))

for _, dotfile := range installed {
if dotfile.Removed {
continue
}
if dotfile.InstallError != nil {
continue
}

installedFiles = append(installedFiles, dotfile.Path)
}

lockfile := installConfig.SourceLockfile
lockfile.InstalledFiles = installedFiles
config.WriteLockfile(lockfile, installConfig.SourceConfig)
}

0 comments on commit a706c60

Please sign in to comment.