-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add built packages json writing to sysroot
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package bringauto_sysroot | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path" | ||
) | ||
|
||
const ( | ||
jsonFileName = "built_packages.json" | ||
) | ||
|
||
// Contains built packages in sysroot and have functions for Json encoding and decoding of built | ||
// packages. | ||
type BuiltPackages struct { | ||
Packages []string | ||
} | ||
|
||
func (builtPackages *BuiltPackages) AddToBuiltPackages(packageName string) error { | ||
err := builtPackages.updateBuiltPackages() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
builtPackages.Packages = append(builtPackages.Packages, packageName) | ||
bytes, err := json.Marshal(builtPackages.Packages) | ||
if err != nil { | ||
return err | ||
} | ||
err = os.WriteFile(path.Join(sysrootDirectoryName, jsonFileName), bytes, 0644) | ||
return err | ||
} | ||
|
||
func (builtPackages *BuiltPackages) updateBuiltPackages() error { | ||
bytes, err := os.ReadFile(path.Join(sysrootDirectoryName, jsonFileName)) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
err = json.Unmarshal(bytes, &builtPackages.Packages) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters