@@ -10,7 +10,7 @@ class Rpm extends Metadata
1010 private $ root ;
1111 private $ createrepo = '/usr/bin/createrepo_c ' ;
1212 private $ createrepoArgs = '-v --compress-type=gz --general-compress-type=gz ' ;
13- private $ modifyrepo = '/usr/bin/modifyrepo_c ' ;
13+ // private $modifyrepo = '/usr/bin/modifyrepo_c';
1414
1515 public function setRoot (string $ root )
1616 {
@@ -20,34 +20,26 @@ public function setRoot(string $root)
2020 /**
2121 * Create metadata files
2222 */
23- public function create ()
23+ public function create (): void
2424 {
25- /**
26- * Check which of createrepo or createrepo_c is present on the system
27- */
25+ // Check which of createrepo or createrepo_c is present on the system
2826 if (!file_exists ($ this ->createrepo )) {
2927 throw new Exception ('Could not find createrepo on the system ' );
3028 }
3129
32- /**
33- * Check if root path exists
34- */
30+ // Check if root path exists
3531 if (!is_dir ($ this ->root )) {
3632 throw new Exception ("Repository root directory ' " . $ this ->root . "' does not exist " );
3733 }
3834
39- /**
40- * If a comps.xml file exists in the root directory, include it in the metadata
41- */
35+ // If a comps.xml file exists in the root directory, include it in the metadata
4236 if (file_exists ($ this ->root . '/comps.xml ' )) {
4337 $ this ->createrepoArgs .= ' --groupfile= ' . $ this ->root . '/comps.xml ' ;
4438 }
4539
4640 $ this ->taskLogSubStepController ->new ('create-metadata ' , 'GENERATING REPOSITORY METADATA ' );
4741
48- /**
49- * Create repository metadata
50- */
42+ // Create repository metadata
5143 $ myprocess = new Process ($ this ->createrepo . ' ' . $ this ->createrepoArgs . ' ' . $ this ->root . '/ ' );
5244 $ myprocess ->setBackground (true );
5345 $ myprocess ->execute ();
@@ -58,9 +50,7 @@ public function create()
5850 */
5951 $ this ->taskController ->addsubpid ($ myprocess ->getPid ());
6052
61- /**
62- * Retrieve output from process
63- */
53+ // Retrieve output from process
6454 $ output = $ myprocess ->getOutput ();
6555
6656 $ this ->taskLogSubStepController ->output ($ output , 'pre ' );
@@ -71,112 +61,15 @@ public function create()
7161
7262 $ myprocess ->close ();
7363
74- /**
75- * Delete comps.xml as it is no longer needed
76- */
77- if (file_exists ($ this ->root . '/comps.xml ' )) {
78- if (!unlink ($ this ->root . '/comps.xml ' )) {
79- throw new Exception ('Could not delete ' . $ this ->root . '/comps.xml ' );
80- }
81- }
82-
83- $ this ->taskLogSubStepController ->completed ();
84-
85- /**
86- * If a 'modules-temp.yaml' file exists in the root directory, include it in the metadata
87- * This file has been given a temporary name to avoid being included automatically by createrepo (which seems to fail to parse it correctly)
88- * So it has to be renamed to modules.yaml and then added to the metadata by modifyrepo
89- */
90- if (file_exists ($ this ->root . '/modules-temp.yaml ' )) {
91- $ this ->taskLogSubStepController ->new ('add-modules ' , 'ADDING MODULES.YAML TO REPOSITORY METADATA ' );
92-
93- /**
94- * Rename to modules.yaml
95- */
96- if (!rename ($ this ->root . '/modules-temp.yaml ' , $ this ->root . '/modules.yaml ' )) {
97- throw new Exception ('Could not rename modules-temp.yaml to modules.yaml ' );
98- }
99-
100- /**
101- * Include modules.yaml in the metadata
102- */
103- $ myprocess = new Process ($ this ->modifyrepo . ' ' . $ this ->root . '/modules.yaml ' . $ this ->root . '/repodata/ ' );
104- $ myprocess ->setBackground (true );
105- $ myprocess ->execute ();
106-
107- /**
108- * Retrieve PID of the launched process
109- * Then write PID to main PID file
110- */
111- $ this ->taskController ->addsubpid ($ myprocess ->getPid ());
112-
113- /**
114- * Retrieve output from process
115- */
116- $ output = $ myprocess ->getOutput ();
117-
118- $ this ->taskLogSubStepController ->output ($ output , 'pre ' );
119-
120- if ($ myprocess ->getExitCode () != 0 ) {
121- throw new Exception ('Failed to add modules.yaml to repository metadata ' );
122- }
123-
124- $ myprocess ->close ();
125-
126- /**
127- * Delete modules.yaml as it is no longer needed
128- */
129- if (file_exists ($ this ->root . '/modules.yaml ' )) {
130- if (!unlink ($ this ->root . '/modules.yaml ' )) {
131- throw new Exception ('Could not delete ' . $ this ->root . '/modules.yaml ' );
64+ // Delete temporary metadata files as they are no longer needed
65+ foreach (['comps.xml ' , 'updateinfo.xml ' , 'modules.yaml ' ] as $ file ) {
66+ if (file_exists ($ this ->root . '/ ' . $ file )) {
67+ if (!unlink ($ this ->root . '/ ' . $ file )) {
68+ throw new Exception ('Could not delete ' . $ this ->root . '/ ' . $ file );
13269 }
13370 }
134-
135- $ this ->taskLogSubStepController ->completed ();
13671 }
13772
138- /**
139- * If updateinfo.xml file exists in the root directory, include it in the metadata
140- */
141- if (file_exists ($ this ->root . '/updateinfo.xml ' )) {
142- $ this ->taskLogSubStepController ->new ('add-updateinfo ' , 'ADDING UPDATEINFO.XML TO REPOSITORY METADATA ' );
143-
144- /**
145- * Include updateinfo.xml in the metadata
146- */
147- $ myprocess = new Process ($ this ->modifyrepo . ' ' . $ this ->root . '/updateinfo.xml ' . $ this ->root . '/repodata/ ' );
148- $ myprocess ->setBackground (true );
149- $ myprocess ->execute ();
150-
151- /**
152- * Retrieve PID of the launched process
153- * Then write PID to main PID file
154- */
155- $ this ->taskController ->addsubpid ($ myprocess ->getPid ());
156-
157- /**
158- * Retrieve output from process
159- */
160- $ output = $ myprocess ->getOutput ();
161-
162- $ this ->taskLogSubStepController ->output ($ output , 'pre ' );
163-
164- if ($ myprocess ->getExitCode () != 0 ) {
165- throw new Exception ('Failed to add updateinfo.xml to repository metadata ' );
166- }
167-
168- $ myprocess ->close ();
169-
170- /**
171- * Delete updateinfo.xml as it is no longer needed
172- */
173- if (file_exists ($ this ->root . '/updateinfo.xml ' )) {
174- if (!unlink ($ this ->root . '/updateinfo.xml ' )) {
175- throw new Exception ('Could not delete ' . $ this ->root . '/updateinfo.xml ' );
176- }
177- }
178-
179- $ this ->taskLogSubStepController ->completed ();
180- }
73+ $ this ->taskLogSubStepController ->completed ();
18174 }
18275}
0 commit comments