@@ -77,6 +77,7 @@ func (c Copr) getRepoConfig() string {
7777 return string (body )
7878}
7979
80+ // red the .repo file in /etc/yum.repos.d
8081func (c Copr ) getRepoFilePath () string {
8182 tmpl := template .Must (template .New ("path" ).Parse (
8283 "/etc/yum.repos.d/_copr:" + HUB + ":{{.Author}}:{{.Reponame}}.repo" ,
@@ -98,26 +99,28 @@ func fileExists(filename string) bool {
9899 return ! info .IsDir ()
99100}
100101
102+ // either writes enabled=1 order enabled=0 into the repo file
101103func writeEnabled (configPath string , enable int ) error {
102104 if ! fileExists (configPath ) {
103105 return errors .New ("File does not exist!" )
104106 }
105- if read , err := os .ReadFile (configPath ); err != nil {
107+ read , err := os .ReadFile (configPath )
108+ if err != nil {
106109 return err
110+ }
107111
112+ if err := os .WriteFile (
113+ configPath ,
114+ []byte (
115+ strings .Replace (string (read ),
116+ "enabled=" + fmt .Sprint (1 - enable ), "enabled=" + fmt .Sprint (enable ), - 1 )), 0 ); err != nil {
117+ return err
108118 } else {
109- if err := os .WriteFile (
110- configPath ,
111- []byte (
112- strings .Replace (string (read ),
113- "enabled=" + fmt .Sprint (1 - enable ), "enabled=" + fmt .Sprint (enable ), - 1 )), 0 ); err != nil {
114- return err
115- } else {
116- return nil
117- }
119+ return nil
118120 }
119121}
120122
123+ // if repo is installed, it enables ist otherwise it installes it
121124func (c Copr ) Enable () {
122125 configPath := c .getRepoFilePath ()
123126
@@ -141,6 +144,7 @@ func (c Copr) Enable() {
141144 os .Exit (0 )
142145}
143146
147+ // if repo is enabled it disables it
144148func (c Copr ) Disable () {
145149 configPath := c .getRepoFilePath ()
146150
@@ -157,6 +161,7 @@ func (c Copr) Disable() {
157161 }
158162}
159163
164+ // remove the repo file
160165func (c Copr ) Remove () {
161166 configPath := c .getRepoFilePath ()
162167
@@ -174,6 +179,7 @@ func (c Copr) Remove() {
174179 os .Exit (0 )
175180}
176181
182+ // list installed coprs
177183func ListCoprs (flags * pflag.FlagSet ) {
178184 repoConfigs , err := os .ReadDir ("/etc/yum.repos.d/" )
179185
0 commit comments