Skip to content

Commit

Permalink
Fix a couple of bugs with ahkpm install (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacc authored Nov 1, 2022
1 parent 638fcad commit c4eb8ac
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/core/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Installer struct{}
func (i Installer) Install(deps DependencyArray) {
pr := NewPackagesRepository()

lm := LockManifestFromCwd()
if deps.Equals(lm.Dependencies()) {
lm, err := LockManifestFromCwd()
if err == nil && deps.Equals(lm.Dependencies()) {
fmt.Println("No dependency changes found. Installing from lockfile.")
os.RemoveAll("ahkpm-modules")
for _, resolvedDep := range lm.Resolved {
Expand Down
6 changes: 3 additions & 3 deletions src/core/lock_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func (lm LockManifest) SaveToCwd() LockManifest {
return lm
}

func LockManifestFromCwd() *LockManifest {
func LockManifestFromCwd() (*LockManifest, error) {
lm, err := LockManifestFromFile("ahkpm.lock")
if err != nil {
utils.Exit(err.Error())
return nil, err
}
return lm
return lm, nil
}

func LockManifestFromFile(path string) (*LockManifest, error) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/packages_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (pr *packagesRepository) GetPackageDependencies(dep ResolvedDependency) ([]
deps := make([]Dependency, 0)
if err == nil {
deps = manifest.Dependencies()
} else if !strings.HasPrefix(err.Error(), "Error reading ahkpm.json") {
} else if !strings.HasPrefix(err.Error(), "Error reading") {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func FileExists(path string) (bool, error) {
func StructFromFile[T any](path string, s *T) (*T, error) {
jsonBytes, err := os.ReadFile(path)
if err != nil {
return nil, errors.New("Error reading ahkpm.json at " + path)
return nil, errors.New("Error reading " + path)
}
err = json.Unmarshal(jsonBytes, s)
if err != nil {
return nil, errors.New("Error unmarshalling ahkpm.json")
return nil, errors.New("Error unmarshalling " + path)
}
return s, nil
}

0 comments on commit c4eb8ac

Please sign in to comment.