(parentPackage *Package)
| 52 | } |
| 53 | |
| 54 | func LoadPackageLock(parentPackage *Package) PackageLock { |
| 55 | removeOld(parentPackage) |
| 56 | packageLockPath := filepath.Join(filepath.Dir(parentPackage.fileName), consts.FilePackageLock) |
| 57 | if fileBytes, err := ioutil.ReadFile(packageLockPath); err != nil { |
| 58 | hash := md5.New() |
| 59 | if _, err := io.WriteString(hash, parentPackage.Name); err != nil { |
| 60 | msg.Warn("Failed on write machine id to hash") |
| 61 | } |
| 62 | |
| 63 | return PackageLock{ |
| 64 | fileName: packageLockPath, |
| 65 | Updated: time.Now(), |
| 66 | Hash: hex.EncodeToString(hash.Sum(nil)), |
| 67 | |
| 68 | Installed: map[string]LockedDependency{}, |
| 69 | } |
| 70 | } else { |
| 71 | lockfile := PackageLock{ |
| 72 | fileName: packageLockPath, |
| 73 | Updated: time.Now(), |
| 74 | Installed: map[string]LockedDependency{}, |
| 75 | } |
| 76 | |
| 77 | if err := json.Unmarshal(fileBytes, &lockfile); err != nil { |
| 78 | utils.HandleError(err) |
| 79 | } |
| 80 | return lockfile |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | func (p PackageLock) Save() { |
| 85 | marshal, err := json.MarshalIndent(&p, "", "\t") |
no test coverage detected