MCPcopy Create free account
hub / github.com/celer-pkg/celer / markAsInstalled

Method markAsInstalled

buildtools/setup_msys2.go:151–194  ·  view source on GitHub ↗
(target string)

Source from the content-addressed store, hash-verified

149}
150
151func (m msys2) markAsInstalled(target string) error {
152 var newCreated bool
153 recordFilePath := filepath.Join(m.rootDir, msys2Packages)
154 if fileio.PathExists(recordFilePath) {
155 newCreated = false
156
157 // Read file.
158 bytes, err := os.ReadFile(recordFilePath)
159 if err != nil {
160 return fmt.Errorf("read msys2_package.txt: %s", err)
161 }
162
163 // Check if the package is already installed.
164 pkgNames := strings.Split(string(bytes), "\n")
165 if slices.Contains(pkgNames, "group:"+target) || slices.Contains(pkgNames, "package:"+target) {
166 return nil
167 }
168 } else {
169 newCreated = true
170 }
171
172 // Open or create file for writing.
173 pkgFile, err := os.OpenFile(recordFilePath, os.O_CREATE|os.O_RDWR|os.O_APPEND, os.ModePerm)
174 if err != nil {
175 return fmt.Errorf("open msys2_package.txt: %s", err)
176 }
177 defer pkgFile.Close()
178
179 // Check if the package is group.
180 isGroupd, err := m.isGroupPackage(target)
181 if err != nil {
182 return fmt.Errorf("check if %s is group package: %s", target, err)
183 }
184
185 // Write package name into file.
186 prefix := expr.If(newCreated, "# Do not modify it, it's generated by celer!\n", "")
187 pkgType := expr.If(isGroupd, "group", "package")
188 content := fmt.Sprintf("%s%s:%s\n", prefix, pkgType, target)
189 if _, err := pkgFile.WriteString(content); err != nil {
190 return fmt.Errorf("write msys2_package.txt: %s", err)
191 }
192
193 return nil
194}
195
196func (m msys2) isMarkedAsInstalled(target string) (bool, error) {
197 // Check if msys2_packages.txt exists.

Callers 2

checkIfInstalledMethod · 0.95
installMethod · 0.95

Calls 4

isGroupPackageMethod · 0.95
PathExistsFunction · 0.92
IfFunction · 0.92
SprintfMethod · 0.80

Tested by

no test coverage detected